-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathcacheTransceiver.cpp
More file actions
1592 lines (1483 loc) · 68.7 KB
/
Copy pathcacheTransceiver.cpp
File metadata and controls
1592 lines (1483 loc) · 68.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "tensorrt_llm/executor/cache_transmission/agent_utils/connection.h"
#include "tensorrt_llm/executor/types.h"
#include <cstdint>
#include <limits>
#include <sstream>
#define UCX_WRAPPER_LIB_NAME "tensorrt_llm_ucx_wrapper"
#if defined(_WIN32)
#include <windows.h>
#define dllOpen(name) LoadLibrary(name ".dll")
#define dllClose(handle) FreeLibrary(static_cast<HMODULE>(handle))
#define dllGetSym(handle, name) static_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name))
#else // For non-Windows platforms
#include <dlfcn.h>
#define dllOpen(name) dlopen("lib" name ".so", RTLD_LAZY)
#define dllClose(handle) dlclose(handle)
#define dllGetSym(handle, name) dlsym(handle, name)
#endif // defined(_WIN32)
#include "tensorrt_llm/batch_manager/cacheFormatter.h"
#include "tensorrt_llm/batch_manager/cacheTransceiver.h"
#include "tensorrt_llm/batch_manager/contextProgress.h"
#include "tensorrt_llm/batch_manager/contextTransferCoordinator.h"
#include "tensorrt_llm/batch_manager/dataTransceiver.h"
#include "tensorrt_llm/batch_manager/kvCacheManager.h"
#include "tensorrt_llm/batch_manager/kvCacheType.h"
#include "tensorrt_llm/batch_manager/kvCacheUtils.h"
#include "tensorrt_llm/batch_manager/llmRequest.h"
#include "tensorrt_llm/batch_manager/mlaCacheFormatter.h"
#include "tensorrt_llm/batch_manager/rnnCacheFormatter.h"
#include "tensorrt_llm/batch_manager/rnnCacheTransBuffer.h"
#include "tensorrt_llm/batch_manager/rnnStateManager.h"
#include "tensorrt_llm/common/envUtils.h"
#include "tensorrt_llm/common/logger.h"
#include "tensorrt_llm/common/tllmDataType.h"
#include "tensorrt_llm/executor/cache_transmission/mpi_utils/connection.h"
#include "tensorrt_llm/executor/dataTransceiverState.h"
#include "tensorrt_llm/executor/serialization.h"
#include "tensorrt_llm/executor/serializeUtils.h"
#include "tensorrt_llm/executor/transferAgent.h"
#include "tensorrt_llm/runtime/utils/mpiUtils.h"
#include "tensorrt_llm/runtime/utils/pgUtils.h"
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <random>
#include <sstream>
#include <thread>
#include <unordered_map>
#include <unordered_set>
namespace tensorrt_llm::batch_manager
{
namespace
{
/// Generate a UUID-like hex string (e.g. "a1b2c3d4-e5f6-7890-abcd-ef1234567890")
/// to uniquely identify a CacheTransceiver instance across gen instances.
std::string generateInstanceId()
{
// The RNG state is comparatively expensive to construct/seed, so keep one
// per thread instead of building it on every call.
static thread_local std::mt19937_64 gen{std::random_device{}()};
std::uniform_int_distribution<uint64_t> dis;
uint64_t a = dis(gen);
uint64_t b = dis(gen);
std::ostringstream oss;
oss << std::hex << std::setfill('0') << std::setw(8) << (a >> 32) << "-" << std::setw(4) << ((a >> 16) & 0xFFFF)
<< "-" << std::setw(4) << (a & 0xFFFF) << "-" << std::setw(4) << (b >> 48) << "-" << std::setw(12)
<< (b & 0xFFFFFFFFFFFF);
return oss.str();
}
} // anonymous namespace
std::mutex CacheTransceiver::mDllMutex;
namespace
{
using RequestIdType = LlmRequest::RequestIdType;
constexpr int kTransferFuturePollIntervalMs = 10;
// Finite status checks are scheduler polls, not terminal deadlines. Pure polls
// use short slices; calls that ask for at least one completion keep bounded
// backpressure by waiting up to the configured future timeout.
std::chrono::milliseconds getTransferFutureWaitInterval(
std::optional<int> const& configuredTimeoutMs, bool const needsProgress)
{
auto waitMs = kTransferFuturePollIntervalMs;
if (configuredTimeoutMs.has_value())
{
waitMs = needsProgress ? configuredTimeoutMs.value()
: std::min(configuredTimeoutMs.value(), kTransferFuturePollIntervalMs);
}
return std::chrono::milliseconds(std::max(1, waitMs));
}
enum class TransferConsensusState : std::uint64_t
{
kCompleted = 1,
kFailed = 2,
kTimedOut = 3,
};
struct TransferStateCounts
{
int completedCount{0};
int failedCount{0};
int timedOutCount{0};
};
struct TransferConsensusOutcome
{
std::unordered_set<RequestIdType> completedRequestIds;
std::unordered_set<RequestIdType> failedRequestIds;
std::unordered_set<RequestIdType> timedOutRequestIds;
};
template <typename CancelFn>
bool requestCancellationNoThrow(RequestIdType requestId, char const* transferKind, CancelFn&& cancelFn) noexcept
{
try
{
return cancelFn();
}
catch (std::exception const& error)
{
TLLM_LOG_ERROR(
"%s cancellation for request %ld failed and will be retried: %s", transferKind, requestId, error.what());
}
catch (...)
{
TLLM_LOG_ERROR("%s cancellation for request %ld failed with an unknown error and will be retried", transferKind,
requestId);
}
return false;
}
long getTransferElapsedMs(std::shared_ptr<LlmRequest> const& request, LlmRequest::TimePoint end)
{
auto const elapsed
= std::chrono::duration_cast<std::chrono::milliseconds>(end - request->getKvCacheTransferStart());
return static_cast<long>(elapsed.count());
}
std::vector<RequestIdType> sortedRequestIds(std::unordered_set<RequestIdType> const& requestIds)
{
std::vector<RequestIdType> result(requestIds.begin(), requestIds.end());
std::sort(result.begin(), result.end());
return result;
}
void appendPackedTransferState(
std::vector<std::uint64_t>& packedStates, RequestIdType requestId, TransferConsensusState state)
{
packedStates.push_back(requestId);
packedStates.push_back(static_cast<std::uint64_t>(state));
}
std::vector<std::uint64_t> gatherPackedTransferStates(
std::shared_ptr<CacheTransceiverComm> const& comm, std::vector<std::uint64_t> const& packedStates)
{
int localSize = static_cast<int>(packedStates.size());
std::vector<int> sizes(comm->getSize());
std::vector<std::uint64_t> gatheredStates;
if (useMPI())
{
comm->allgather(&localSize, sizes.data(), 1, mpi::MpiType::kINT32);
std::vector<int> displs(comm->getSize());
size_t totalSize = 0;
for (int i = 0; i < comm->getSize(); i++)
{
displs[i] = static_cast<int>(totalSize);
totalSize += sizes[i];
}
gatheredStates.resize(totalSize);
comm->allgatherv(packedStates.data(), static_cast<int>(packedStates.size()), mpi::MpiType::kUINT64,
gatheredStates.data(), sizes, displs, mpi::MpiType::kUINT64);
}
else
{
comm->allgather(&localSize, std::ref(sizes), {});
size_t totalSize = std::accumulate(sizes.begin(), sizes.end(), 0);
gatheredStates.resize(totalSize);
comm->allgatherv(std::ref(packedStates), std::ref(gatheredStates), std::cref(sizes), {});
}
return gatheredStates;
}
TransferConsensusOutcome reduceTransferStates(std::shared_ptr<CacheTransceiverComm> const& comm,
std::unordered_set<RequestIdType> const& completedRequestIds,
std::unordered_set<RequestIdType> const& failedRequestIds,
std::unordered_set<RequestIdType> const& timedOutRequestIds)
{
std::vector<std::uint64_t> localStates;
localStates.reserve((completedRequestIds.size() + failedRequestIds.size() + timedOutRequestIds.size()) * 2);
for (auto const requestId : completedRequestIds)
{
if (failedRequestIds.find(requestId) == failedRequestIds.end())
{
appendPackedTransferState(localStates, requestId, TransferConsensusState::kCompleted);
}
}
for (auto const requestId : failedRequestIds)
{
appendPackedTransferState(localStates, requestId, TransferConsensusState::kFailed);
}
for (auto const requestId : timedOutRequestIds)
{
appendPackedTransferState(localStates, requestId, TransferConsensusState::kTimedOut);
}
int const syncSize = (comm != nullptr) ? comm->getSize() : 1;
auto const gatheredStates
= ((comm != nullptr) && syncSize > 1) ? gatherPackedTransferStates(comm, localStates) : std::move(localStates);
constexpr size_t kPackedStateFields = 2;
TLLM_CHECK_WITH_INFO(gatheredStates.size() % kPackedStateFields == 0,
"Packed transfer state consensus payload must contain request/state pairs.");
std::unordered_map<RequestIdType, TransferStateCounts> stateCounts;
for (size_t idx = 0; idx < gatheredStates.size(); idx += kPackedStateFields)
{
auto const requestId = gatheredStates.at(idx);
auto const state = static_cast<TransferConsensusState>(gatheredStates.at(idx + 1));
auto& counts = stateCounts[requestId];
switch (state)
{
case TransferConsensusState::kCompleted: counts.completedCount++; break;
case TransferConsensusState::kFailed: counts.failedCount++; break;
case TransferConsensusState::kTimedOut: counts.timedOutCount++; break;
}
}
TransferConsensusOutcome outcome;
for (auto const& [requestId, counts] : stateCounts)
{
auto const terminalCount = counts.completedCount + counts.failedCount;
if (counts.timedOutCount > 0)
{
outcome.timedOutRequestIds.insert(requestId);
}
if (terminalCount == syncSize && (counts.failedCount > 0 || counts.timedOutCount > 0))
{
outcome.failedRequestIds.insert(requestId);
}
else if (counts.completedCount == syncSize)
{
outcome.completedRequestIds.insert(requestId);
}
}
return outcome;
}
TransferConsensusOutcome reduceTransferStates(std::shared_ptr<CacheTransceiverComm> const& firstComm,
std::shared_ptr<CacheTransceiverComm> const& secondComm,
std::unordered_set<RequestIdType> const& completedRequestIds,
std::unordered_set<RequestIdType> const& failedRequestIds,
std::unordered_set<RequestIdType> const& timedOutRequestIds)
{
auto const firstOutcome
= reduceTransferStates(firstComm, completedRequestIds, failedRequestIds, timedOutRequestIds);
return reduceTransferStates(
secondComm, firstOutcome.completedRequestIds, firstOutcome.failedRequestIds, firstOutcome.timedOutRequestIds);
}
void recordLocalTransferOutcome(RequestIdType requestId, std::shared_ptr<LlmRequest> request, bool failed,
std::unordered_set<RequestIdType>& completedRequestIds, std::unordered_set<RequestIdType>& failedRequestIds,
std::unordered_map<RequestIdType, std::shared_ptr<LlmRequest>>& requestsAwaitingConsensus)
{
requestsAwaitingConsensus[requestId] = std::move(request);
if (failed)
{
completedRequestIds.erase(requestId);
failedRequestIds.insert(requestId);
}
else if (failedRequestIds.find(requestId) == failedRequestIds.end())
{
completedRequestIds.insert(requestId);
}
}
void eraseLocalTransferOutcome(RequestIdType requestId, std::unordered_set<RequestIdType>& completedRequestIds,
std::unordered_set<RequestIdType>& failedRequestIds,
std::unordered_map<RequestIdType, std::shared_ptr<LlmRequest>>& requestsAwaitingConsensus)
{
completedRequestIds.erase(requestId);
failedRequestIds.erase(requestId);
requestsAwaitingConsensus.erase(requestId);
}
} // namespace
std::unique_ptr<BaseCacheTransceiver> CacheTransceiverFactory::createCacheTransceiver(
kv_cache_manager::BaseKVCacheManager* cacheManager, runtime::ModelConfig const& modelConfig,
runtime::WorldConfig const& worldConfig, executor::kv_cache::CacheState::AttentionType attentionType,
std::optional<executor::CacheTransceiverConfig> cacheTransceiverConfig)
{
if (!cacheTransceiverConfig.has_value() || !cacheTransceiverConfig.value().getBackendType().has_value())
{
TLLM_LOG_INFO("CacheTransceiver is disabled.");
return nullptr;
}
TLLM_CHECK_WITH_INFO(!common::getEnvDisaggEnableInflightCancel(),
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 is supported only by the PyExecutor C++ NIXL transceiver path; "
"the legacy C++ executor does not provide the required deferred cleanup and poison escalation.");
auto backendType = cacheTransceiverConfig.value().getBackendType();
if (backendType.value() == executor::CacheTransceiverConfig::BackendType::DEFAULT)
{
if (common::getEnvUseUCXKvCache())
{
backendType = executor::CacheTransceiverConfig::BackendType::UCX;
TLLM_LOG_INFO("Enable UCX KV cache transport.");
}
else if (common::getEnvUseNixlKvCache())
{
backendType = executor::CacheTransceiverConfig::BackendType::NIXL;
TLLM_LOG_INFO("Enable NIXL KV cache transport.");
}
else if (common::getEnvUseMooncakeKvCache())
{
backendType = executor::CacheTransceiverConfig::BackendType::MOONCAKE;
TLLM_LOG_INFO("Enable MOONCAKE KV cache transport.");
}
else if (common::getEnvUseMPIKvCache())
{
backendType = executor::CacheTransceiverConfig::BackendType::MPI;
TLLM_LOG_INFO("Enable MPI KV cache transport.");
TLLM_LOG_WARNING("MPI KV cache transport is deprecated, please use UCX or NIXL instead.");
}
else
{
backendType = executor::CacheTransceiverConfig::BackendType::NIXL;
}
}
cacheTransceiverConfig.value().setBackendType(backendType);
executor::kv_cache::CacheState::ModelConfig cacheStateCfg{
modelConfig.getNumKvHeadsPerLayer(), modelConfig.getSizePerHead(), modelConfig.getTokensPerBlock()};
auto ppSize = worldConfig.getPipelineParallelism();
std::vector<SizeType32> attentionLayerNumPerPP(ppSize, 0);
for (int ppRank = 0; ppRank < ppSize; ppRank++)
{
attentionLayerNumPerPP[ppRank] = modelConfig.getNbAttentionLayers(ppSize, ppRank);
}
return std::make_unique<CacheTransceiver>(cacheManager, cacheStateCfg, worldConfig, attentionLayerNumPerPP,
modelConfig.getKvDataType(), attentionType, cacheTransceiverConfig);
}
CacheTransceiver::CacheTransceiver(kv_cache_manager::BaseKVCacheManager* cacheManager,
executor::kv_cache::CacheState::ModelConfig const& cacheStateModelCfg, runtime::WorldConfig const& worldConfig,
std::vector<SizeType32> const& attentionLayerNumPerPP, tensorrt_llm::DataType dataType,
executor::kv_cache::CacheState::AttentionType attentionType,
std::optional<executor::CacheTransceiverConfig> cacheTransceiverConfig,
std::vector<SizeType32> const& rnnLayerNumPerPP)
: mCacheTransceiverConfig{cacheTransceiverConfig}
{
using tensorrt_llm::batch_manager::kv_cache_manager::CacheFormatter;
TLLM_CHECK_WITH_INFO(mCacheTransceiverConfig.has_value(), "CacheTransceiverConfig is not set.");
auto const backendType = mCacheTransceiverConfig.value().getBackendType();
TLLM_CHECK_WITH_INFO(
backendType.has_value() && (backendType.value() != executor::CacheTransceiverConfig::BackendType::DEFAULT),
" CacheTransceiverConfig::BackendType is not set.");
if (common::getEnvDisaggEnableInflightCancel())
{
auto const nixlBackend = common::getEnvNixlBackend();
TLLM_CHECK_WITH_INFO(
backendType.value() == executor::CacheTransceiverConfig::BackendType::NIXL && nixlBackend == "UCX",
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 is experimental and currently supported only with the "
"NIXL cache transceiver and the UCX NIXL backend.");
TLLM_CHECK_WITH_INFO(mCacheTransceiverConfig->getKvTransferTimeoutMs().has_value(),
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 requires kv_transfer_timeout_ms to enforce a finite deadline.");
TLLM_CHECK_WITH_INFO(!common::getEnvDisableKVCacheTransferOverlap(),
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 requires asynchronous KV cache transfer; "
"TRTLLM_DISABLE_KV_CACHE_TRANSFER_OVERLAP=1 is not supported.");
TLLM_CHECK_WITH_INFO(!common::getEnvDisaggLayerwise(),
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 does not support layer-wise KV cache transfer.");
TLLM_CHECK_WITH_INFO(!common::getEnvTryZCopyForKVCacheTransfer(),
"TRTLLM_DISAGG_ENABLE_INFLIGHT_CANCEL=1 does not support zero-copy KV cache transfer because request "
"blocks cannot be quarantined after an unquiesced cancellation.");
}
if (useMPI())
{
mGroupComm = std::make_shared<CacheTransceiverComm>(std::addressof(tensorrt_llm::mpi::MpiComm::session()));
}
else
{
mGroupComm = std::make_shared<CacheTransceiverComm>(tensorrt_llm::pg_utils::get_world_pg());
}
// Generate instance ID on rank 0 and broadcast to all ranks in the session
// so every rank in the same gen/ctx instance shares the same ID.
{
if (mGroupComm->getRank() == 0)
{
mInstanceId = generateInstanceId();
}
if (useMPI())
{
int len = static_cast<int>(mInstanceId.size());
tensorrt_llm::mpi::MpiComm::session().bcast(&len, 1, mpi::MpiType::kINT32, 0);
mInstanceId.resize(len);
tensorrt_llm::mpi::MpiComm::session().bcast(mInstanceId.data(), len, mpi::MpiType::kCHAR, 0);
}
else
{
// PG path: rank 0 sends via allgather, others receive.
constexpr int kUuidLen = 36;
std::vector<char> sendBuf(kUuidLen, '\0');
if (mGroupComm->getRank() == 0)
{
std::copy_n(mInstanceId.begin(), std::min<size_t>(mInstanceId.size(), kUuidLen), sendBuf.begin());
}
std::vector<char> recvBuf(kUuidLen * mGroupComm->getSize(), '\0');
mGroupComm->allgather(std::ref(sendBuf), std::ref(recvBuf), {});
// Take rank 0's segment.
mInstanceId = std::string(recvBuf.begin(), recvBuf.begin() + kUuidLen);
}
}
// Calibrate steady_clock across ranks so that cross-node allgather
// in batchUpdateKVCacheTransferBW can compare time points.
// globalSteadyClockOffset() reads a single process-global copy shared with
// the nanobind module, so if the Python runtime already calibrated the offset
// (PyExecutor::_set_global_steady_clock_offset) it is visible here and we skip;
// the pure-C++ path performs the calibration below.
// The check-and-set is guarded by a mutex so that CacheTransceiver instances
// constructed concurrently in the same process (e.g. multi-engine serving) do
// not race on the shared offset or issue mismatched collectives.
{
static std::mutex sSteadyClockCalibrationMutex;
std::lock_guard<std::mutex> lock(sSteadyClockCalibrationMutex);
if (!globalSteadyClockOffset().has_value())
{
using Duration = LlmRequest::Duration;
// Synchronize all ranks immediately before sampling the local clock so
// every rank measures from a consistent point.
if (useMPI())
{
tensorrt_llm::mpi::MpiComm::session().barrier();
}
else
{
// CacheTransceiverComm exposes no barrier primitive, so use a cheap
// allgather as a pseudo-barrier for the process-group path.
int64_t const dummy = 0;
std::vector<int64_t> dummyRecv(mGroupComm->getSize(), 0);
mGroupComm->allgather(dummy, std::ref(dummyRecv), {});
}
auto localNow = std::chrono::steady_clock::now();
auto localNs = std::chrono::duration_cast<std::chrono::nanoseconds>(localNow.time_since_epoch()).count();
// Allgather timestamps from all ranks
std::vector<int64_t> allNs(mGroupComm->getSize(), 0);
if (useMPI())
{
tensorrt_llm::mpi::MpiComm::session().allgather(&localNs, allNs.data(), 1, mpi::MpiType::kINT64);
}
else
{
mGroupComm->allgather(localNs, std::ref(allNs), {});
}
// Offset = rank0's timestamp - my timestamp (same formula as Python)
auto offsetNs = allNs[0] - localNs;
globalSteadyClockOffset() = Duration(offsetNs);
TLLM_LOG_INFO(mGroupComm->getRank(),
"CacheTransceiver: set global steady clock offset = %.6f sec for rank %d",
static_cast<double>(offsetNs) / 1e9, mGroupComm->getRank());
}
}
if (worldConfig.isTensorParallel() || worldConfig.isContextParallel())
{
mGroupTensorParaComm = std::make_shared<CacheTransceiverComm>(
mGroupComm->split(worldConfig.getPipelineParallelRank(), worldConfig.getRank()));
}
if (worldConfig.isPipelineParallel())
{
auto const ppGroupColor = worldConfig.getTensorParallelRank() * worldConfig.getContextParallelism()
+ worldConfig.getContextParallelRank();
mGroupPipeParaComm
= std::make_shared<CacheTransceiverComm>(mGroupComm->split(ppGroupColor, worldConfig.getRank()));
}
int kvFactor = 2;
if (cacheManager->getCacheType() == kv_cache_manager::CacheType::kSELFKONLY)
{
kvFactor = 1;
}
mCacheState
= std::make_unique<executor::kv_cache::CacheState>(cacheStateModelCfg, worldConfig, attentionLayerNumPerPP,
dataType, attentionType, kvFactor, cacheManager->isEnableBlockReuse(), cacheManager->isEnablePartialReuse(),
cacheManager->isEnableIndexerKCache(), cacheManager->getIndexerKCacheIndexHeadDim(),
cacheManager->getIndexerKCacheQuantBlockSize(), cacheManager->getIndexerKCacheUseFp4());
if (mCacheState->getParallelConfig().mEnableAttentionDP)
{
int dpSize = mCacheState->getParallelConfig().mDPsize;
// dpRank is derived from the tensor parallel rank, which already accounts for CP.
// Layout: rank = ppRank * (TP * CP) + tpRank * CP + cpRank.
// getTensorParallelRank() correctly extracts tpRank regardless of CP.
int dpRank = mCacheState->getParallelConfig().mDPrank;
// <PP,DP,TP,CP>
mGroupDataComm = std::make_shared<CacheTransceiverComm>(mGroupComm->split(dpRank, worldConfig.getRank()));
if (worldConfig.isTensorParallel() || worldConfig.isContextParallel())
{
// Group ranks with same (ppRank, dpRank) accounting for CP.
mGroupTPInDPComm = std::make_shared<CacheTransceiverComm>(
mGroupComm->split(worldConfig.getPipelineParallelRank() * dpSize + dpRank, worldConfig.getRank()));
}
}
bool isMLA = attentionType == executor::kv_cache::CacheState::AttentionType::kMLA;
std::optional<size_t> maxNumTokens = mCacheTransceiverConfig.value().getMaxTokensInBuffer();
mCacheTransBufferManagers.push_back(
std::make_unique<kv_cache_manager::CacheTransBufferManager>(cacheManager, maxNumTokens));
if (isMLA && cacheManager->isEnableIndexerKCache())
{
mCacheTransBufferManagers.push_back(
std::make_unique<kv_cache_manager::CacheTransBufferManager>(cacheManager, maxNumTokens, true));
}
// Unified pool path (CppMambaHybridCacheManager): build RnnModelConfig from
// LinearAttentionMetadata. Detected by rnnLayerNumPerPP being non-empty.
if (!rnnLayerNumPerPP.empty())
{
auto const& blockManager = cacheManager->getBlockManager();
auto const& linearMeta = blockManager.getLinearAttentionMetadata();
TLLM_CHECK_WITH_INFO(linearMeta.has_value(), "LinearAttentionMetadata not found for unified pool RNN config");
executor::kv_cache::CacheState::RnnModelConfig rnnModelCfg{};
rnnModelCfg.mNumHeads = linearMeta->rnnNumHeads;
rnnModelCfg.mHeadDim = linearMeta->rnnHeadDim;
rnnModelCfg.mDState = linearMeta->rnnDState;
rnnModelCfg.mDConv = linearMeta->rnnDConv;
rnnModelCfg.mNGroups = linearMeta->rnnNGroups;
rnnModelCfg.mHiddenSize = linearMeta->rnnHeadDim * linearMeta->rnnNumHeads;
rnnModelCfg.mConvSectionLayout = static_cast<executor::kv_cache::CacheState::RnnModelConfig::ConvSectionLayout>(
linearMeta->rnnConvSectionLayout);
// Derive actual SSM and conv dtypes from metadata byte sizes.
// Pool dtype is UINT8 (raw byte storage), so we cannot use pool->getDataType().
// Only the byte size matters for split/concat kernel stride calculations — the actual
// dtype enum is not interpreted numerically, just used for getDTypeSize() dispatch.
auto dtypeFromSize = [](SizeType32 size) -> tensorrt_llm::DataType
{
switch (size)
{
case 4: return tensorrt_llm::DataType::kFLOAT;
case 2: return tensorrt_llm::DataType::kBF16;
case 1: return tensorrt_llm::DataType::kFP8;
default: TLLM_THROW("Unsupported RNN state dtype size: %d", size);
}
};
TLLM_CHECK_WITH_INFO(linearMeta->rnnSsmDtypeSize > 0, "rnnSsmDtypeSize not set in LinearAttentionMetadata");
TLLM_CHECK_WITH_INFO(linearMeta->rnnConvDtypeSize > 0, "rnnConvDtypeSize not set in LinearAttentionMetadata");
tensorrt_llm::DataType ssmDtype = dtypeFromSize(linearMeta->rnnSsmDtypeSize);
tensorrt_llm::DataType convDtype = dtypeFromSize(linearMeta->rnnConvDtypeSize);
mCacheState->setRnnConfig(rnnModelCfg, rnnLayerNumPerPP, convDtype, ssmDtype);
// Create RnnCacheTransBufferManager for unified pool path.
mRnnCacheTransBufferManager
= std::make_unique<rnn_state_manager::RnnCacheTransBufferManager>(cacheManager, *mCacheState, maxNumTokens);
TLLM_LOG_INFO(
"Unified pool RNN config: numHeads=%d, headDim=%d, dState=%d, dConv=%d, "
"nGroups=%d, hiddenSize=%d, convSectionLayout=%d",
rnnModelCfg.mNumHeads, rnnModelCfg.mHeadDim, rnnModelCfg.mDState, rnnModelCfg.mDConv, rnnModelCfg.mNGroups,
rnnModelCfg.mHiddenSize, static_cast<int>(rnnModelCfg.mConvSectionLayout));
}
mCacheTransBufferManagerPtrs.clear();
mCacheTransBufferManagerPtrs.reserve(mCacheTransBufferManagers.size() + (mRnnCacheTransBufferManager ? 1 : 0));
for (auto& manager : mCacheTransBufferManagers)
{
mCacheTransBufferManagerPtrs.push_back(manager.get());
}
if (mRnnCacheTransBufferManager)
{
mCacheTransBufferManagerPtrs.push_back(mRnnCacheTransBufferManager.get());
}
if (backendType.value() == executor::CacheTransceiverConfig::BackendType::UCX)
{
std::lock_guard<std::mutex> lock(mDllMutex);
executor::kv_cache::promoteHostLibraryToGlobalScope();
mWrapperLibHandle = dllOpen(UCX_WRAPPER_LIB_NAME);
TLLM_CHECK_WITH_INFO(
mWrapperLibHandle != nullptr, "UCX wrapper library is not open correctly. error : %s", dlerror());
auto load_sym = [](void* handle, char const* name)
{
void* ret = dllGetSym(handle, name);
TLLM_CHECK_WITH_INFO(ret != nullptr,
"Unable to load UCX wrapper library symbol, possible cause is that TensorRT LLM library is not "
"built with UCX support, please rebuild in UCX-enabled environment.");
return ret;
};
std::unique_ptr<tensorrt_llm::executor::kv_cache::ConnectionManager> (*makeUcxConnectionManager)();
*(void**) (&makeUcxConnectionManager) = load_sym(mWrapperLibHandle, "makeUcxConnectionManager");
mManager = makeUcxConnectionManager();
TLLM_LOG_INFO("UCX Connection Manager created");
}
else if (backendType.value() == executor::CacheTransceiverConfig::BackendType::NIXL)
{
auto rnnState
= mCacheState->hasRnnConfig() ? std::make_optional(mCacheState->getRnnCacheState()) : std::nullopt;
mManager = std::make_unique<tensorrt_llm::executor::kv_cache::AgentConnectionManager>(
mCacheTransBufferManagerPtrs, *mCacheState, "nixl", rnnState);
TLLM_LOG_INFO("NIXL Connection Manager created");
}
else if (backendType.value() == executor::CacheTransceiverConfig::BackendType::MOONCAKE)
{
auto rnnState
= mCacheState->hasRnnConfig() ? std::make_optional(mCacheState->getRnnCacheState()) : std::nullopt;
mManager = std::make_unique<tensorrt_llm::executor::kv_cache::AgentConnectionManager>(
mCacheTransBufferManagerPtrs, *mCacheState, "mooncake", rnnState);
TLLM_LOG_INFO("MOONCAKE Connection Manager created");
}
else if (backendType.value() == executor::CacheTransceiverConfig::BackendType::MPI)
{
mMpiWorldComm = std::addressof(tensorrt_llm::mpi::MpiComm::world());
mManager = std::make_unique<executor::kv_cache::MpiConnectionManager>(mMpiWorldComm);
TLLM_LOG_INFO("MPI Connection Manager created");
}
else
{
TLLM_THROW("Unsupported cache transceiver backend type ");
}
auto makeFormatter = [cacheManager, isMLA, this]()
{
std::vector<kv_cache_manager::CacheTransBufferManager*> kvBufferPtrs;
kvBufferPtrs.reserve(mCacheTransBufferManagers.size());
for (auto& mgr : mCacheTransBufferManagers)
{
kvBufferPtrs.push_back(mgr.get());
}
return createCacheFormatter(cacheManager, kvBufferPtrs, isMLA);
};
auto makeRnnFormatter = [this, cacheManager]() -> std::unique_ptr<RnnCacheFormatter>
{
// Unified pool path (CppMambaHybridCacheManager)
if (mCacheState->hasRnnConfig() && mRnnCacheTransBufferManager != nullptr)
{
return std::make_unique<RnnCacheFormatter>(cacheManager, mRnnCacheTransBufferManager.get());
}
return nullptr;
};
auto makeCacheTransferLayer
= [&]() { return CacheTransferLayer(*mCacheState, makeFormatter(), makeRnnFormatter()); };
mCacheSender
= std::make_unique<CacheSender>(mManager.get(), worldConfig.getRank(), makeCacheTransferLayer(), mInstanceId);
mCacheReceiver
= std::make_unique<CacheReceiver>(mManager.get(), worldConfig.getRank(), makeCacheTransferLayer(), mInstanceId);
// Keep automatic enablement within the currently qualified C++ NIXL/UCX TP1/CP1 pipeline topology.
bool const coordinatorTopologyEligible = worldConfig.getPipelineParallelism() > 1 && useMPI()
&& backendType.value() == executor::CacheTransceiverConfig::BackendType::NIXL
&& common::getEnvNixlBackend() == "UCX" && worldConfig.getTensorParallelism() == 1
&& worldConfig.getContextParallelism() == 1 && !mCacheState->getParallelConfig().mEnableAttentionDP;
if (worldConfig.getPipelineParallelism() > 1 && useMPI())
{
TLLM_CHECK(mGroupPipeParaComm != nullptr);
constexpr std::uint64_t kCoordinatorProtocolVersion = 1;
std::uint64_t const localVersion = coordinatorTopologyEligible ? kCoordinatorProtocolVersion : 0;
bool const cancellationEnabled = common::getEnvDisaggEnableInflightCancel();
std::uint64_t const localProtocolMode = (localVersion << 1) | static_cast<std::uint64_t>(cancellationEnabled);
std::vector<std::uint64_t> protocolModes(static_cast<std::size_t>(mGroupPipeParaComm->getSize()));
mGroupPipeParaComm->allgather(&localProtocolMode, protocolModes.data(), 1, mpi::MpiType::kUINT64);
TLLM_CHECK_WITH_INFO(std::all_of(protocolModes.begin(), protocolModes.end(),
[&](std::uint64_t const mode) { return mode == localProtocolMode; }),
"Context-transfer consensus protocol version or cancellation mode differs across PP ranks.");
if (localVersion != 0)
{
mContextTransferCoordinator = std::make_unique<ContextTransferCoordinator>(mGroupPipeParaComm);
TLLM_LOG_INFO(
"Enable asynchronous context-transfer consensus version %llu for PP group of size %d; in-flight "
"cancellation=%s.",
static_cast<unsigned long long>(kCoordinatorProtocolVersion), mGroupPipeParaComm->getSize(),
cancellationEnabled ? "enabled" : "disabled");
}
}
initializeCommState();
}
CacheTransceiver::~CacheTransceiver()
{
// Stop sender/receiver workers while the connection manager and transfer
// plugin are still alive. The workers can access both during termination.
mCacheSender.reset();
mCacheReceiver.reset();
mContextTransferCoordinator.reset();
if (mWrapperLibHandle)
{
std::lock_guard<std::mutex> lock(mDllMutex);
dllClose(mWrapperLibHandle);
}
}
void CacheTransceiver::initializeCommState()
{
mCommState = std::addressof(mCacheSender->getCommState());
}
std::vector<char> CacheTransceiver::getSerializedDataTransceiverState() const
{
TLLM_CHECK(mCommState != nullptr && mCacheState != nullptr);
executor::DataTransceiverState state;
state.setCommState(*mCommState);
state.setCacheState(*mCacheState);
// Only this API marks the state; context responses leave it unset.
state.setIsArbitraryTransferState(true);
return executor::Serialization::serialize(state);
}
void CacheTransceiver::setContextState(LlmRequest* llmRequest)
{
TLLM_CHECK(llmRequest && llmRequest->isContextOnlyRequest());
auto contextState = std::make_unique<executor::DataTransceiverState>();
contextState->setCommState(*mCommState);
contextState->setCacheState(*mCacheState);
if (!llmRequest->hasDraftTokens())
{
llmRequest->setContextPhaseParams(
executor::ContextPhaseParams{{}, llmRequest->mRequestId, contextState.release(), std::nullopt});
}
else
{
llmRequest->setContextPhaseParams(executor::ContextPhaseParams{
{}, llmRequest->mRequestId, contextState.release(), *llmRequest->getDraftTokens()});
}
}
void CacheTransceiver::respondAndSendAsync(std::shared_ptr<LlmRequest> llmRequest)
{
TLLM_CHECK(llmRequest && llmRequest->isContextOnlyRequest());
llmRequest->setState(LlmRequestState::kDISAGG_CONTEXT_TRANS_IN_PROGRESS);
// If context phase params is already set, it means that the KV cache
// transfer is already in progress.
if (llmRequest->getContextPhaseParams().has_value())
{
if (llmRequest->getContextProgress() == nullptr)
{
TLLM_LOG_WARNING("Request %ld is already responding", llmRequest->mRequestId);
}
return;
}
setContextState(llmRequest.get());
auto future = mCacheSender->sendAsync(llmRequest);
mSenderFutures.emplace_back(std::move(llmRequest), std::move(future));
}
void CacheTransceiver::respondAndSendLayerWise(
RequestVector const& requests, std::shared_ptr<ContextProgress> const& progress)
{
for (auto const& llmRequest : requests)
{
TLLM_CHECK(llmRequest && llmRequest->isContextOnlyRequest());
TLLM_CHECK(!llmRequest->getContextPhaseParams().has_value());
llmRequest->setContextProgress(progress);
TLLM_LOG_DEBUG("Request %ld is being sent layer-wise.", llmRequest->mRequestId);
llmRequest->setState(LlmRequestState::kDISAGG_CONTEXT_INIT_AND_TRANS);
setContextState(llmRequest.get());
auto future = mCacheSender->sendAsync(llmRequest);
mSenderFutures.emplace_back(llmRequest, std::move(future));
}
}
void CacheTransceiver::requestAndReceiveSync(std::shared_ptr<LlmRequest> llmRequest)
{
TLLM_CHECK(llmRequest && llmRequest->isGenerationOnlyRequest());
auto const requestId = llmRequest->mRequestId;
auto const contextRequestId = llmRequest->getContextPhaseParams().value().getReqId();
TLLM_LOG_DEBUG("Synchronous KV cache receive request %zu, context request %zu waiting for native completion.",
requestId, contextRequestId);
try
{
auto future = mCacheReceiver->receiveAsync(llmRequest);
future.get();
}
catch (std::exception const& err)
{
llmRequest->setState(LlmRequestState::kDISAGG_TRANS_ERROR);
llmRequest->setKvCacheTransferEnd(LlmRequest::getSteadyClockNow());
TLLM_LOG_ERROR("Synchronous KV cache receive request %zu, context request %zu failed: %s", requestId,
contextRequestId, err.what());
return;
}
catch (...)
{
llmRequest->setState(LlmRequestState::kDISAGG_TRANS_ERROR);
llmRequest->setKvCacheTransferEnd(LlmRequest::getSteadyClockNow());
TLLM_LOG_ERROR("Synchronous KV cache receive request %zu, context request %zu failed with an unknown error",
requestId, contextRequestId);
return;
}
if (llmRequest->getState() == LlmRequestState::kDISAGG_TRANS_ERROR)
{
TLLM_LOG_ERROR("Synchronous KV cache receive request %zu, context request %zu completed with an error state.",
requestId, contextRequestId);
return;
}
llmRequest->setState(LlmRequestState::kDISAGG_GENERATION_TRANS_COMPLETE);
}
void CacheTransceiver::requestAndReceiveAsync(std::shared_ptr<LlmRequest> llmRequest)
{
TLLM_CHECK(llmRequest && llmRequest->isGenerationOnlyRequest());
auto const requestId = llmRequest->mRequestId;
if (std::find_if(mRequesterFutures.begin(), mRequesterFutures.end(),
[requestId](auto const& pair) { return pair.first->mRequestId == requestId; })
!= mRequesterFutures.end())
{
TLLM_LOG_WARNING("Request ID %zu is already in mRequestFutures.", requestId);
return;
}
llmRequest->setKvCacheTransferStart(LlmRequest::getSteadyClockNow());
auto future = mCacheReceiver->receiveAsync(llmRequest);
auto* requestPtr = llmRequest.get();
mRequesterFutures.emplace_back(std::move(llmRequest), std::move(future));
requestPtr->setState(LlmRequestState::kDISAGG_GENERATION_TRANS_IN_PROGRESS);
}
std::vector<LlmRequest::RequestIdType> gatherRequestIds(
std::shared_ptr<CacheTransceiverComm> const& mComm, std::vector<LlmRequest::RequestIdType> const& requestIds)
{
int localSize = static_cast<int>(requestIds.size());
std::vector<int> sizes(mComm->getSize());
std::vector<LlmRequest::RequestIdType> retData;
if (useMPI())
{
mComm->allgather(&localSize, sizes.data(), 1, mpi::MpiType::kINT32);
std::vector<int> displs(mComm->getSize());
size_t totalSize = 0;
for (int i = 0; i < mComm->getSize(); i++)
{
displs[i] = totalSize;
totalSize += sizes[i];
}
retData.resize(totalSize);
mComm->allgatherv(requestIds.data(), static_cast<int>(requestIds.size()), mpi::MpiType::kUINT64, retData.data(),
sizes, displs, mpi::MpiType::kUINT64);
}
else
{
mComm->allgather(&localSize, std::ref(sizes), {});
size_t totalSize = std::accumulate(sizes.begin(), sizes.end(), 0);
retData.resize(totalSize);
mComm->allgatherv(std::ref(requestIds), std::ref(retData), std::cref(sizes), {});
}
return retData;
}
void batchUpdateKVCacheTransferBW(
std::shared_ptr<CacheTransceiverComm> const& comm, std::vector<LlmRequest*> const& requests)
{
// Key-based merge: each rank serializes (requestId, start, end, size)
// tuples and we use allgatherv so ranks may have different request counts.
// The merge matches by requestId, not by position — this tolerates
// ordering differences and count mismatches across ranks.
namespace su = executor::serialize_utils;
int const worldSize = comm->getSize();
// --- Serialize local entries keyed by requestId ---
std::size_t const numReqs = requests.size();
std::ostringstream oStream;
su::serialize(numReqs, oStream);
for (auto* req : requests)
{
su::serialize(req->getContextPhaseParams().value().getReqId(), oStream);
su::serialize(req->getKvCacheTransferStart(), oStream);
su::serialize(req->getKvCacheTransferEnd(), oStream);
su::serialize(req->getKvCacheSize(), oStream);
}
auto str = oStream.str();
std::vector<char> sendBuffer(str.begin(), str.end());
int const sendSize = static_cast<int>(sendBuffer.size());
// --- Step 1: allgather per-rank buffer sizes ---
std::vector<int> recvCounts(worldSize, 0);
if (useMPI())
{
comm->allgather(&sendSize, recvCounts.data(), 1, mpi::MpiType::kINT32);
}
else
{
comm->allgather(sendSize, std::ref(recvCounts), {});
}
// --- Step 2: allgatherv the serialized data ---
std::vector<int> displs(worldSize, 0);
int totalRecvSize = 0;
for (int r = 0; r < worldSize; ++r)
{
displs[r] = totalRecvSize;
totalRecvSize += recvCounts[r];
}
std::vector<char> recvBuffer(totalRecvSize, 0);
if (useMPI())
{
comm->allgatherv(sendBuffer.data(), sendSize, mpi::MpiType::kCHAR, recvBuffer.data(), recvCounts, displs,
mpi::MpiType::kCHAR);
}
else
{
comm->allgatherv(std::ref(sendBuffer), std::ref(recvBuffer), recvCounts, {});
}
// --- Step 3: Deserialize and merge by requestId ---
using TimePoint = executor::RequestPerfMetrics::TimePoint;
using ReqIdType = LlmRequest::RequestIdType;
struct MergedEntry
{
TimePoint minStart = TimePoint::max();
TimePoint maxEnd = TimePoint::min();
std::size_t totalSize = 0;
};
std::unordered_map<ReqIdType, MergedEntry> merged;
su::VectorWrapBuf<char> strbuf(recvBuffer);
std::istream is(&strbuf);
for (int rank = 0; rank < worldSize; ++rank)
{
auto rankNumReqs = su::deserialize<std::size_t>(is);
for (std::size_t i = 0; i < rankNumReqs; ++i)
{
auto rid = su::deserialize<ReqIdType>(is);
auto start = su::deserialize<TimePoint>(is);
auto end = su::deserialize<TimePoint>(is);
auto size = su::deserialize<std::size_t>(is);
auto& entry = merged[rid];
entry.minStart = std::min(entry.minStart, start);
entry.maxEnd = std::max(entry.maxEnd, end);
entry.totalSize += size;
}
}
// --- Step 4: Update local requests ---
for (auto* req : requests)
{
auto reqId = req->getContextPhaseParams().value().getReqId();
auto it = merged.find(reqId);
if (it != merged.end())
{
req->setKvCacheTransferStart(it->second.minStart);
req->setKvCacheTransferEnd(it->second.maxEnd);
req->setKvCacheSize(it->second.totalSize);
}
}
}
RequestStatuses CacheTransceiver::checkContextTransferStatus(
std::optional<int> const& atLeastRequestNum, bool markComplete)
{
bool const blockAll = !atLeastRequestNum.has_value();