Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
/cpp/tensorrt_llm/batch_manager/blockKey* @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tensorrt_llm/batch_manager/evictionPolicy* @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tensorrt_llm/batch_manager/kvCache* @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tensorrt_llm/batch_manager/kv_cache_manager_v2 @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tensorrt_llm/nanobind/batch_manager/kvCacheManager* @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tests/unit_tests/batch_manager/blockKey* @NVIDIA/trt-llm-kv-cache-manager-devs
/cpp/tests/unit_tests/batch_manager/evictionPolicy* @NVIDIA/trt-llm-kv-cache-manager-devs
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ static-analysis-files: &static_analysis_files |
)$

# Global exclude: vendored code + trtllm-gen FMHA artifacts (cubin pointers, export headers, cuda_ptx)
exclude: '(^triton_kernels/|trtllmGenKernels/fmha/cubin/kernelMetaInfo\.h$|cubin\.cpp$|cubin\.h$|trtllmGenKernels/fmha/trtllmGen_fmha_export/|trtllmGenKernels/fmha/cuda_ptx/)'
exclude: '(^cpp/tensorrt_llm/common/sha256/|^triton_kernels/|trtllmGenKernels/fmha/cubin/kernelMetaInfo\.h$|cubin\.cpp$|cubin\.h$|trtllmGenKernels/fmha/trtllmGen_fmha_export/|trtllmGenKernels/fmha/cuda_ptx/)'

default_install_hook_types: [pre-commit, commit-msg]
repos:
Expand Down
10 changes: 9 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (c) 2011-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

This project is licensed under the Apache 2.0 license, whose full license text is available below.

Expand All @@ -12,6 +12,14 @@ file headers for specific copyright and license information.

Below is a list of other projects that have portions contained by this project:

--------------------------------------------------------------------------------
Bitcoin Core
--------------------------------------------------------------------------------
Original Source: https://github.com/bitcoin/bitcoin
Copyright (c) 2009-2026 The Bitcoin Core developers
Copyright (c) 2009-2026 Bitcoin Developers
Licensed under the MIT License

--------------------------------------------------------------------------------
causal-conv1d
--------------------------------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion cpp/tensorrt_llm/batch_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ else() # Windows
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()

# Include kv_cache_manager_v2 C++ sources.
include(${CMAKE_CURRENT_SOURCE_DIR}/kv_cache_manager_v2/CMakeLists.txt)
list(APPEND SRCS ${KV_CACHE_MANAGER_V2_SRCS})

add_library(${BATCH_MANAGER_STATIC_TARGET} STATIC ${SRCS})
target_include_directories(
${BATCH_MANAGER_STATIC_TARGET}
PUBLIC ${xgrammar_source_dir}/3rdparty/picojson
${xgrammar_source_dir}/3rdparty/dlpack/include
${xgrammar_source_dir}/include)
${xgrammar_source_dir}/include
${KV_CACHE_MANAGER_V2_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/tensorrt_llm/common/sha256)

set_target_properties(
${BATCH_MANAGER_STATIC_TARGET}
Expand Down
2 changes: 1 addition & 1 deletion cpp/tensorrt_llm/batch_manager/kvCacheManagerV2Utils.cu
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ CUresult launchBatchedCopyImpl(
}
uint32_t const nbSplits = lowBandwidth ? 1 : divUp(nbBytes, grainBytes * ctaSize * 2);
void* args[] = {(void*) pTasks, (void*) &nbBytes};
static CUkernel const kernel = [] -> CUkernel
static CUkernel const kernel = []() -> CUkernel
{
cudaKernel_t kernel = nullptr;
TLLM_CUDA_CHECK(cudaGetKernel(&kernel, reinterpret_cast<void const*>(&batchedCopy<N>)));
Expand Down
9 changes: 2 additions & 7 deletions cpp/tensorrt_llm/batch_manager/kvCacheManagerV2Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include "kv_cache_manager_v2/common.h"
#include "tensorrt_llm/batch_manager/llmRequest.h"
#include "tensorrt_llm/kernels/kvCacheIndex.h"
#include "tensorrt_llm/runtime/iBuffer.h"
Expand All @@ -34,13 +35,7 @@ using ITensor = tensorrt_llm::runtime::ITensor;

namespace tensorrt_llm::batch_manager::kv_cache_manager_v2
{
struct DiskAddress
{
int fd;
ssize_t pos;
};

using MemAddress = std::uintptr_t;
// DiskAddress and MemAddress are defined in kv_cache_manager_v2/common.h (included above).

// Please make sure to align with the definition in tensorrt_llm/runtime/kv_cache_manager_v2/_common.py
constexpr tk::KVCacheIndex::UnderlyingType BAD_PAGE_INDEX = -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: Copyright (c) 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.

# Sources for the C++ KVCacheManagerV2 implementation. These are added to the
# tensorrt_llm_batch_manager_static target by the parent CMakeLists.txt.

# Bitcoin Core SHA-256 (vendored, MIT; see common/sha256/README.md) — needed by
# blockRadixTree.cpp. Slimmed to the single-block CSHA256 path: portable scalar
# core + runtime dispatch (sha256.cpp) plus a per-architecture hardware
# transform. Plain C++17; the include root common/sha256 is added on the
# batch_manager target so "sha256.h" resolves.
set(SHA256_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../common/sha256)
set(SHA256_SRCS ${SHA256_DIR}/sha256.cpp)
# x86/x86-64: Intel SHA-NI transform.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|i[3-6]86")
set(SHA256_X86_SHANI ${SHA256_DIR}/sha256_x86_shani.cpp)
set_source_files_properties(
${SHA256_X86_SHANI} PROPERTIES COMPILE_OPTIONS "-msse4.1;-msse4;-msha")
list(APPEND SHA256_SRCS ${SHA256_X86_SHANI})
endif()
# AArch64: ARMv8 crypto-extension (SHA-256) transform.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64")
set(SHA256_ARM_SHANI ${SHA256_DIR}/sha256_arm_shani.cpp)
set_source_files_properties(
${SHA256_ARM_SHANI} PROPERTIES COMPILE_OPTIONS "-march=armv8-a+crypto")
list(APPEND SHA256_SRCS ${SHA256_ARM_SHANI})
endif()

set(KV_CACHE_MANAGER_V2_SRCS
kv_cache_manager_v2/common.cpp
kv_cache_manager_v2/config.cpp
kv_cache_manager_v2/lifeCycleRegistry.cpp
kv_cache_manager_v2/utils/cudaEvent.cpp
kv_cache_manager_v2/utils/hostMem.cpp
kv_cache_manager_v2/cudaVirtMem.cpp
kv_cache_manager_v2/storage/config.cpp
kv_cache_manager_v2/storage/core.cpp
kv_cache_manager_v2/evictionController.cpp
kv_cache_manager_v2/copyEngine.cpp
kv_cache_manager_v2/blockRadixTree.cpp
kv_cache_manager_v2/eventManager.cpp
kv_cache_manager_v2/page.cpp
kv_cache_manager_v2/storageManager.cpp
kv_cache_manager_v2/introspection.cpp
kv_cache_manager_v2/kvCache.cpp
kv_cache_manager_v2/kvCacheManager.cpp
${SHA256_SRCS})

# Headers and sources are co-located; the include root is batch_manager/ so that
# #include "kv_cache_manager_v2/common.h" resolves correctly. NOTE: this file is
# include()'d (not add_subdirectory()'d), so CMAKE_CURRENT_SOURCE_DIR is already
# batch_manager/ — no PARENT_SCOPE needed.
set(KV_CACHE_MANAGER_V2_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Loading
Loading