Repository navigation
[#20363][perf] Prefer the copy engine for KVCM2 host-tier copies on coherent links - #20364
lucifer1004 wants to merge 1 commit into
Conversation
…s on coherent links BatchedPageCopier used its SM copy kernel on every NVLink-C2C link. Make the copy engine the default there too, keep the kernel behind TLLM_KV_CACHE_MANAGER_V2_COHERENT_COPY_KERNEL=1, and keep forcing the kernel when host registration is chunked. Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com>
|
Test report (branch diff applied on a build from an earlier main, SM107, single node):
|
|
Cross-referencing two PRs on the same selection in What we measured on SM107 with a coherent NVLink-C2C link (Kimi K3, 8 GPUs over 2 nodes, KVCacheManagerV2 with the host tier on, details in #20363):
The trade-off as I see it:
If you prefer #20426, I'm happy to close this PR and add our SM107 numbers (and a run with its variable set) there. If the default should change, this PR is ready for review. It has been tested on SM107: the new gtest passed 6/6, and both the default path and the opt-in kernel path were exercised. |
|
[by Claude Code] @yizhang-nv Could you review this PR? Thanks! |
1 similar comment
|
[by Claude Code] @yizhang-nv Could you review this PR? Thanks! |
Description
Fixes #20363.
BatchedPageCopier(#18541) moves KVCacheManagerV2 pages between GPU and the host tier with an SM copy kernel on coherent (NVLink-C2C) links and withcuMemcpyBatchAsyncon PCIe. This PR makes the copy engine the default on coherent links as well; the kernel stays available throughTLLM_KV_CACHE_MANAGER_V2_COHERENT_COPY_KERNEL=1, and chunked host registration still forces the kernel as before.Why (details and data in #20363):
Changes:
batchedPageCopy.cu:computeConfigs()selects the path throughdetail::selectCopyKernel(coherentLink, chunkedRegistration, kernelOnCoherentLink); the opt-in is read from the environment when the copier is constructed. The selected path is logged at DEBUG.batchedPageCopy.h: declaresdetail::kCoherentCopyKernelEnvanddetail::selectCopyKernel(), and updates the class comment.No behaviour change on PCIe or with chunked host registration. With the copy engine selected,
pageIndexLocation()reportskHost, which the cold-page codec and the storage manager already handle (it is the PCIe path today).Test Coverage
New cases in
cpp/tests/unit_tests/batch_manager/kvCacheManagerV2ColdPageCopyTest.cu:CopyEngineIsDefaultOnEveryLink,CopyKernelOptInAppliesOnlyToCoherentLinks,ChunkedRegistrationAlwaysSelectsCopyKernel: the selection truth table.CoherentCopyKernelEnv/BatchedPageCopierPathTest.SelectsPathAndRoundTripsPages/{Unset,Value0,Value1}: constructs a copier on GPU 0 with the variable unset /0/1, checkskernelEnabled(), bothKernelConfig::useKernelandpageIndexLocation()against the expected selection for the detected topology, then offloads 8 pages to mapped pinned host memory and onboards them back through two permutations and checks the bytes. On a coherent system this exercises both paths; on PCIe both instances use the copy engine.Validation:
-std=c++20). On SM107 (coherent link, branch diff applied on a build from an earlier main) it passed 6/6; not run on a PCIe machine yet.PR Checklist
Dev Engineer Review
BatchedPageCopiernow uses the copy engine by default. It uses the kernel when host registration is chunked, or whenTLLM_KV_CACHE_MANAGER_V2_COHERENT_COPY_KERNELis exactly"1"on a coherent link.QA Engineer Review
kvCacheManagerV2ColdPageCopyTest.cu, a GPU unit test for copy-path selection and page-copy round trips under unset,"0", and"1"environment values. It also tests chunked-registration selection and, for CUDA versions below 12.8, the kernel fallback for multiple index segments.kvCacheManagerV2ColdPageCopyTest. No integration test-list entry applies to this unit test.-std=c++20), but GPU execution is pending.Per-File QA Perspective
cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2/batchedPageCopy.cu— Verify default copy-engine selection, exact"1"opt-in behavior on coherent links, and forced kernel selection with chunked registration. Also verify copies on PCIe and coherent systems.cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2/batchedPageCopy.h— Verify thatpageIndexLocation()matches the selected copy path, since the kernel requires device-resident indices and the copy engine requires host-resident indices.cpp/tests/unit_tests/batch_manager/kvCacheManagerV2ColdPageCopyTest.cu— Tests path selection and D2H/H2D page transfers with permuted host slots. It is a unit test, registered through CMake; it is not listed in the integration CI or manual-QA lists.