From e7865b393ddfae3e6a48958c2560b7164d9301db Mon Sep 17 00:00:00 2001 From: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com> Date: Mon, 25 Aug 2025 05:17:40 +0000 Subject: [PATCH] None: Update TargetsInfo to support CP in disagg later Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com> --- .../cache_transmission/cacheSplitConcat.cu | 37 ++- .../cache_transmission/cacheSplitConcat.h | 1 + .../multi_gpu/cacheTransceiverTest.cpp | 311 +++++++++++++++--- 3 files changed, 292 insertions(+), 57 deletions(-) diff --git a/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.cu b/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.cu index 38c7eecaadc..73343b9d1e3 100644 --- a/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.cu +++ b/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.cu @@ -57,9 +57,12 @@ TargetRanksInfo TargetRanksInfoForDP( auto const selfPPNum = selfParConfig.mPipelineParallelism; auto const peerTPNum = peerParConfig.mTensorParallelism; auto const selfTPNum = selfParConfig.mTensorParallelism; + auto const peerCPNum = peerParConfig.mContextParallelism; + auto const selfCPNum = selfParConfig.mContextParallelism; - auto const selfTPRank = selfRank % selfParConfig.mTensorParallelism; - auto const selfPPRank = selfRank / selfParConfig.mTensorParallelism; + auto const selfTPRank = selfRank % selfTPNum; + auto const selfPPRank = selfRank / (selfTPNum * selfCPNum); + auto const selfCPRank = (selfRank % (selfTPNum * selfCPNum)) / selfTPNum; int peerPPRankStart = 0; int mDomainPPSize = 1; @@ -108,13 +111,35 @@ TargetRanksInfo TargetRanksInfoForDP( peerTPRankEnd = peerTPRankStart + mDomainTPSize; } + int mDomainCPSize = 1; + int peerCPRankStart = 0; + int peerCPRankEnd = 0; + for (auto val : {peerCPNum, selfCPNum}) + { + TLLM_CHECK(isPowerOfTwo(val)); + } + if (selfCPNum <= peerCPNum) + { + mDomainCPSize = peerCPNum / selfCPNum; + peerCPRankStart = selfCPRank * mDomainCPSize; + peerCPRankEnd = (selfCPRank + 1) * mDomainCPSize; + } + else + { + peerCPRankStart = selfCPRank / (selfCPNum / peerCPNum); + peerCPRankEnd = peerCPRankStart + mDomainCPSize; + } + std::vector retRanks; for (int i = peerTPRankStart; i < peerTPRankEnd; i++) { - for (int j = peerPPRankStart; j < peerPPRankEnd; j++) + for (int j = peerCPRankStart; j < peerCPRankEnd; j++) { - int irank = j * peerTPNum + i; - retRanks.push_back(irank); + for (int k = peerPPRankStart; k < peerPPRankEnd; k++) + { + int irank = (k * peerTPNum * peerCPNum) + (j * peerTPNum) + i; + retRanks.push_back(irank); + } } } @@ -131,7 +156,7 @@ TargetRanksInfo TargetRanksInfoForDP( = (peerNbHeadsPerLayer * peerTPSizePerDPGroup) / (selfNbHeadsPerLayer * selfTPSizePerDPGroup); } - return {mDomainPPSize, mDomainTPSize, std::move(retRanks), mDupHeadFactor, mPeerDupHeadFactor}; + return {mDomainPPSize, mDomainTPSize, mDomainCPSize, std::move(retRanks), mDupHeadFactor, mPeerDupHeadFactor}; } TargetRanksInfo targetIRanks( diff --git a/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.h b/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.h index c5f32704494..eca8c9a21a6 100644 --- a/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.h +++ b/cpp/tensorrt_llm/executor/cache_transmission/cacheSplitConcat.h @@ -36,6 +36,7 @@ struct TargetRanksInfo { int mDomainPPSize; int mDomainTPSize; + int mDomainCPSize; std::vector mIRanks; int mDupHeadFactor; int mPeerDupHeadFactor; diff --git a/cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp b/cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp index 4b513ae57f9..a3d809b8860 100644 --- a/cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp +++ b/cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp @@ -1438,69 +1438,278 @@ TEST(targetTest, CacheStateNODP) bool const isMLA = true; int const kvFactor = 2; - int contextPP = 2; - int contextTP = 4; - int contextCP = 1; - int genPP = 2; - int genTP = 2; - int genCP = 1; - bool const contextEnableDP = false; - bool const genEnableDP = false; - - auto const verifyContext = [&](int contextRank, std::vector const& expectRanks, int expectPPDomain, - int expectTPDomain, bool expectNeedSend) + auto const verifyContext = [&](int contextRank, tr::WorldConfig const& contextWC, tr::WorldConfig const& genWC, + std::vector const& expectRanks, int expectPPDomain, int expectTPDomain, + int expectCPDomain, bool expectNeedSend) { auto attentionType = isMLA ? texec::kv_cache::CacheState::AttentionType::kMLA : texec::kv_cache::CacheState::AttentionType::kDEFAULT; - auto const contextCache = tensorrt_llm::executor::kv_cache::CacheState{numLayers, numHeads, sizePerHead, - tokensPerBlock, contextTP, contextPP, contextCP, dataType, attentionType, kvFactor, contextEnableDP, 0, 0}; - auto const genCache = tensorrt_llm::executor::kv_cache::CacheState{numLayers, numHeads, sizePerHead, - tokensPerBlock, genTP, genPP, genCP, dataType, attentionType, kvFactor, genEnableDP, 0, 0}; + auto const sharedModelConfig + = texec::kv_cache::CacheState::ModelConfig{std::vector(numLayers, numHeads), sizePerHead, tokensPerBlock}; + auto const contextCache + = texec::kv_cache::CacheState(sharedModelConfig, contextWC, dataType, attentionType, kvFactor); + auto const genCache = texec::kv_cache::CacheState(sharedModelConfig, genWC, dataType, attentionType, kvFactor); - auto const contextTragetInfo + auto const contextTargetInfo = tensorrt_llm::executor::kv_cache::TargetRanksInfoForDP(genCache, contextCache, contextRank); - EXPECT_EQ(expectRanks, contextTragetInfo.mIRanks); - EXPECT_EQ(expectPPDomain, contextTragetInfo.mDomainPPSize); - EXPECT_EQ(expectTPDomain, contextTragetInfo.mDomainTPSize); + EXPECT_EQ(expectRanks, contextTargetInfo.mIRanks); + EXPECT_EQ(expectPPDomain, contextTargetInfo.mDomainPPSize); + EXPECT_EQ(expectTPDomain, contextTargetInfo.mDomainTPSize); + EXPECT_EQ(expectCPDomain, contextTargetInfo.mDomainCPSize); EXPECT_EQ(expectNeedSend, MLACacheFormatter::needSendCache(contextCache, genCache, contextRank)); }; - verifyContext( - /*contextRank*/ 0, /*expectRanks*/ {0}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ true); - verifyContext( - /*contextRank*/ 1, /*expectRanks*/ {0}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ false); - verifyContext( - /*contextRank*/ 2, /*expectRanks*/ {1}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ true); - verifyContext( - /*contextRank*/ 3, /*expectRanks*/ {1}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ false); - verifyContext( - /*contextRank*/ 4, /*expectRanks*/ {2}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ true); - verifyContext( - /*contextRank*/ 5, /*expectRanks*/ {2}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ false); - verifyContext( - /*contextRank*/ 6, /*expectRanks*/ {3}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ true); - verifyContext( - /*contextRank*/ 7, /*expectRanks*/ {3}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectNeedSend*/ false); + // TP shrinks from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 4, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 4, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 5, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 6, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 7, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ false); + } - contextTP = 2; - genTP = 4; + // TP grows from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 4, /*ppSize*/ 2, /*cpSize*/ 1}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 1}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {4, 5}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {6, 7}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + } - verifyContext( - /*contextRank*/ 0, /*expectRanks*/ {0, 1}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 2, /*expectNeedSend*/ true); - verifyContext(/*contextRank*/ 1, /*expectRanks*/ {2, 3}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 2, - /*expectNeedSend*/ true); - verifyContext( - /*contextRank*/ 2, /*expectRanks*/ {4, 5}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 2, /*expectNeedSend*/ true); - verifyContext(/*contextRank*/ 3, /*expectRanks*/ {6, 7}, /*expectPPDomain*/ 1, /*expectTPDomain*/ 2, - /*expectNeedSend*/ true); - contextPP = 1; - verifyContext( - /*contextRank*/ 0, /*expectRanks*/ {0, 4, 1, 5}, /*expectPPDomain*/ 2, /*expectTPDomain*/ 2, - /*expectNeedSend*/ true); - verifyContext(/*contextRank*/ 1, /*expectRanks*/ {2, 6, 3, 7}, /*expectPPDomain*/ 2, /*expectTPDomain*/ 2, - /*expectNeedSend*/ true); + // TP as well as PP grow from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 1, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 4, /*ppSize*/ 2, /*cpSize*/ 1}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5}, + /*expectPPDomain*/ 2, /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2, 6, 3, 7}, + /*expectPPDomain*/ 2, /*expectTPDomain*/ 2, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + } + + // PP grows while TP shrinks from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 1, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 1, /*ppSize*/ 2, /*cpSize*/ 1}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 1}, /*expectPPDomain*/ + 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 1}, /*expectPPDomain*/ + 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 1, /*expectNeedSend*/ false); + } + + // CP grows from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, + /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, + /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {4, 6}, + /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {5, 7}, + /*expectPPDomain*/ 1, /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + } + + // TP as well as CP grow from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 4, /*ppSize*/ 2, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2, 6, 3, 7}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {8, 12, 9, 13}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {10, 14, 11, 15}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + } + + // TP shrinks while CP grows from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 4, /*ppSize*/ 1, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 1, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + } + + // PP as well as CP grow from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 4, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 2, 6}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 5, 3, 7}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {8, 12, 10, 14}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {9, 13, 11, 15}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + } + + // PP shrinks while CP grows from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 4, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 4, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {4, 6}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 5, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {5, 7}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 6, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {4, 6}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 7, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {5, 7}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + } + + // TP as well as PP shrink while CP grows from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 4, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 2, /*ppSize*/ 1, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 4, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 5, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 2}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + verifyContext( + /*contextRank*/ 6, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 7, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {1, 3}, /*expectPPDomain*/ 1, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 2, /*expectNeedSend*/ false); + } + + // TP, CP grow while PP shrinks from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 2, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 4, /*ppSize*/ 1, /*cpSize*/ 2}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2, 6, 3, 7}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 2, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 3, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {2, 6, 3, 7}, + /*expectPPDomain*/ 1, + /*expectTPDomain*/ 2, /*expectCPDomain*/ 2, /*expectNeedSend*/ true); + } + + // PP, CP grow while TP shrinks from context to generation. + { + tr::WorldConfig const contextWC{/*tpSize*/ 2, /*ppSize*/ 1, /*cpSize*/ 1}; + tr::WorldConfig const genWC{/*tpSize*/ 1, /*ppSize*/ 2, /*cpSize*/ 4}; + verifyContext( + /*contextRank*/ 0, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5, 2, 6, 3, 7}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 4, /*expectNeedSend*/ true); + verifyContext( + /*contextRank*/ 1, /*contextWC*/ contextWC, /*genWC*/ genWC, /*expectRanks*/ {0, 4, 1, 5, 2, 6, 3, 7}, + /*expectPPDomain*/ 2, + /*expectTPDomain*/ 1, /*expectCPDomain*/ 4, /*expectNeedSend*/ false); + } } TEST(targetTest, CacheStateContextDP)