From e937d2a7faaa49b6507f96249116b69ada8113d0 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:29:02 +0000 Subject: [PATCH 01/37] [None][build] make GoogleTest discovery prefixes optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add TEST_PREFIX to the arguments accepted by add_tllm_gtest and forward a nonempty prefix to gtest_discover_tests. This lets component tests customize their discovered CTest names through the shared helper. Build optional discovery arguments in both add_tllm_gtest and the legacy add_gtest helper. Omit the TEST_PREFIX keyword when no prefix is supplied, and use each helper’s matching parsed argument variable to preserve explicit prefixes. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tests/CMakeLists.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 5ba58455a7a8..d2253ff776a9 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -42,7 +42,7 @@ endforeach() function(add_tllm_gtest test_name) set(options FULL_STACK NO_GTEST_MAIN REQUIRES_GPU) - set(one_value_args TIMEOUT OWNER) + set(one_value_args TIMEOUT OWNER TEST_PREFIX) set(multi_value_args SOURCES LINK_LIBRARIES LABELS) cmake_parse_arguments(PARSE_ARGV 1 ARG "${options}" "${one_value_args}" "${multi_value_args}") @@ -88,8 +88,13 @@ function(add_tllm_gtest test_name) if(ARG_TIMEOUT) list(APPEND test_properties TIMEOUT "${ARG_TIMEOUT}") endif() - gtest_discover_tests(${test_name} DISCOVERY_MODE PRE_TEST DISCOVERY_TIMEOUT 30 - PROPERTIES LABELS "${ARG_LABELS}" ${test_properties}) + set(discovery_args) + if(NOT "${ARG_TEST_PREFIX}" STREQUAL "") + list(APPEND discovery_args TEST_PREFIX "${ARG_TEST_PREFIX}") + endif() + gtest_discover_tests( + ${test_name} ${discovery_args} DISCOVERY_MODE PRE_TEST DISCOVERY_TIMEOUT 30 + PROPERTIES LABELS "${ARG_LABELS}" ${test_properties}) add_dependencies(google-tests ${test_name}) if(ARG_OWNER) @@ -127,9 +132,12 @@ function(add_gtest test_name test_src) list(APPEND test_properties TIMEOUT "${ARGS_TIMEOUT}") endif() + set(discovery_args) + if(NOT "${ARGS_TEST_PREFIX}" STREQUAL "") + list(APPEND discovery_args TEST_PREFIX "${ARGS_TEST_PREFIX}") + endif() gtest_discover_tests( - ${test_name} - TEST_PREFIX "${ARGS_TEST_PREFIX}" + ${test_name} ${discovery_args} PROPERTIES ${test_properties} DISCOVERY_MODE PRE_TEST # WAR for DLL discovery on windows. From eeca770940c6fff5bf05405d80f98b6a958b2236 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 11:01:14 +0000 Subject: [PATCH 02/37] build: reject monolithic linkage without explicit FULL_STACK Add tllm_assert_test_is_component_local and invoke it after establishing link dependencies for each non-FULL_STACK add_tllm_gtest target. Inspect the target's direct LINK_LIBRARIES and fail configuration if it contains the TensorRT-LLM shared-library target, with an actionable instruction to use FULL_STACK explicitly. This closes the bypass where LINK_LIBRARIES could name the monolith while the test omitted FULL_STACK. Explicit full-stack tests and normal component dependencies retain their existing behavior. The guard covers direct target linkage, as specified in the component-local test proposal; transitive dependency checks remain a separate build-graph concern. Validation: configure-only probes using the actual assertion and helper reject direct monolithic linkage, accept focused component linkage and accept FULL_STACK with supplemental libraries. Reconfigure the real CUDA 13.4/SM80, MPI, Torch and NIXL project, build stringUtilsTest and run its four existing host cases. Formatting and commit hooks pass. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tests/CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index d2253ff776a9..8a45a945cb14 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -40,6 +40,16 @@ foreach(owner common runtime executor batch-manager kernel) add_custom_target(${owner}-tests) endforeach() +function(tllm_assert_test_is_component_local target) + get_target_property(link_libraries ${target} LINK_LIBRARIES) + if("${SHARED_TARGET}" IN_LIST link_libraries) + message( + FATAL_ERROR + "${target} links the full TensorRT-LLM library; use FULL_STACK explicitly" + ) + endif() +endfunction() + function(add_tllm_gtest test_name) set(options FULL_STACK NO_GTEST_MAIN REQUIRES_GPU) set(one_value_args TIMEOUT OWNER TEST_PREFIX) @@ -77,6 +87,9 @@ function(add_tllm_gtest test_name) endif() endif() target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBRARIES}) + if(NOT ARG_FULL_STACK) + tllm_assert_test_is_component_local(${test_name}) + endif() target_compile_features(${test_name} PRIVATE cxx_std_20) target_compile_definitions(${test_name} PRIVATE TOP_LEVEL_DIR="${TOP_LEVEL_DIR}") From 38f147a65a2d9db8bfbeecd0d9bce2dbc8221af5 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Fri, 23 Oct 2026 07:31:19 +0000 Subject: [PATCH 03/37] [None][build] reject full-library interface links in component tests Extend tllm_assert_test_is_component_local to inspect the link interface of each target linked directly by a component test. Previously, the guard only rejected the full TensorRT-LLM shared target in the test's own LINK_LIBRARIES, allowing a dependency to introduce that library through its interface without requiring FULL_STACK. Reject dependencies whose INTERFACE_LINK_LIBRARIES directly contains SHARED_TARGET and report both the test and the dependency responsible. Skip entries that are not CMake targets. This checks one level of target interfaces; it does not recursively traverse the dependency graph or evaluate generator expressions. Validation: isolated CMake configurations accept component-only links and dependencies with no link interface, and reject a dependency whose interface directly links the full library. Staged whitespace checks pass. Full project configuration and build were not run. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tests/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 8a45a945cb14..88dc6350e2e0 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -48,6 +48,18 @@ function(tllm_assert_test_is_component_local target) "${target} links the full TensorRT-LLM library; use FULL_STACK explicitly" ) endif() + foreach(dep IN LISTS link_libraries) + if(NOT TARGET ${dep}) + continue() + endif() + get_target_property(dep_interface ${dep} INTERFACE_LINK_LIBRARIES) + if("${SHARED_TARGET}" IN_LIST dep_interface) + message( + FATAL_ERROR + "${target} links ${dep}, which interface-links the full TensorRT-LLM library; use FULL_STACK explicitly" + ) + endif() + endforeach() endfunction() function(add_tllm_gtest test_name) From f4dd4095eee81d6986cc01c6fac9ecd236a64784 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Fri, 23 Oct 2026 07:35:00 +0000 Subject: [PATCH 04/37] [None][build] defer component-test linkage checks until directory end Run tllm_assert_test_is_component_local through cmake_language(DEFER) for tests registered without FULL_STACK. The immediate check only saw links established inside add_tllm_gtest, so subsequent commands could add the full TensorRT-LLM library directly or through a dependency interface without being rejected. Deferring the assertion lets it inspect the link properties after the current directory finishes processing. Use cmake_language(EVAL CODE) to expand the function-local test_name when scheduling the call, and pass the captured name as a bracket argument. DEFER alone would evaluate the variable after the function scope ends, losing the target name and causing a configuration error. Validation: - Isolated CMake configuration accepts multiple component tests, verifying that each deferred call retains its own target name. - Isolated CMake configuration rejects a direct full-library link added after test registration. - Isolated CMake configuration rejects a dependency interface link to the full library added after test registration. - Repository cmake-format hook and staged whitespace checks pass. Full project configuration and build were not run. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tests/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 88dc6350e2e0..ae59fd4a9c34 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -100,7 +100,11 @@ function(add_tllm_gtest test_name) endif() target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBRARIES}) if(NOT ARG_FULL_STACK) - tllm_assert_test_is_component_local(${test_name}) + cmake_language( + EVAL + CODE + "cmake_language(DEFER CALL tllm_assert_test_is_component_local [[${test_name}]])" + ) endif() target_compile_features(${test_name} PRIVATE cxx_std_20) target_compile_definitions(${test_name} From 0593d85751e26983a83469e38319f60c9ee541dd Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:39:23 +0000 Subject: [PATCH 05/37] build: extract the logits kernel family and its test Move logitsBitmask.cu out of kernels_src into the explicit tllm::kernel_logits static library. Link logitsBitmaskTest only to that family and runtime buffers, and register it with kernel-tests and GPU scheduling labels/resource locking. Add a reusable kernel-library helper that requires explicit sources, removes them from the residual source lists, and preserves PIC, CUDA device linking, C++/CUDA 20, and the existing architecture selection. Export the extracted families from the product with whole-archive and matching link overrides, while keeping test links ordinary. Validation: logitsBitmaskTest builds in both the product configuration and a fresh component-only project. Its dependency graph excludes libtensorrt_llm.so, kernels_src, residual common/runtime libraries, batch manager, executor, and Torch. Six GPU cases are discovered with the GPU resource lock. GPU execution is unavailable on this host. Source-ownership checks preserve the existing compilation counts. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 7 +++ cpp/tensorrt_llm/kernels/CMakeLists.txt | 5 ++ .../kernels/kernelComponents.cmake | 57 +++++++++++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++- 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cpp/tensorrt_llm/kernels/kernelComponents.cmake diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index 8fa6c33c8eee..aa37050fb825 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -280,6 +280,13 @@ target_link_libraries( $ $) +foreach(component IN LISTS TLLM_KERNEL_COMPONENT_TARGETS) + target_link_libraries(${SHARED_TARGET} + PRIVATE $) + set_property(TARGET ${SHARED_TARGET} + PROPERTY LINK_LIBRARY_OVERRIDE_${component} WHOLE_ARCHIVE) +endforeach() + # Components also link each other normally; retain all component exports here. set_property(TARGET ${SHARED_TARGET} PROPERTY LINK_LIBRARY_OVERRIDE_tllm_common_error WHOLE_ARCHIVE) diff --git a/cpp/tensorrt_llm/kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/CMakeLists.txt index 5f2190da30bf..314b92643072 100644 --- a/cpp/tensorrt_llm/kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/CMakeLists.txt @@ -105,6 +105,11 @@ if(FAST_BUILD) STATUS "FAST_BUILD enabled for kernels: using -O1 for CUDA compilation") endif() +include(kernelComponents.cmake) +set(TLLM_KERNEL_COMPONENT_TARGETS + ${TLLM_KERNEL_COMPONENT_TARGETS} + PARENT_SCOPE) + # Marlin NVFP4: build Ada/Hopper kernels and the dense W4A16/repack kernels used # on SM12x. Unsupported device passes emit empty kernel stubs. file(GLOB_RECURSE MARLIN_SRC "marlin/*.cu" "marlin/*.cpp") diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake new file mode 100644 index 000000000000..473c21c626c5 --- /dev/null +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -0,0 +1,57 @@ +# +# SPDX-FileCopyrightText: Copyright (c) 1993-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. +# + +function(add_tllm_kernel_library target) + set(multi_value_args SOURCES LINK_LIBRARIES INCLUDE_DIRECTORIES) + cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "${multi_value_args}") + if(ARG_UNPARSED_ARGUMENTS + OR ARG_KEYWORDS_MISSING_VALUES + OR NOT ARG_SOURCES) + message(FATAL_ERROR "${target}: explicit kernel sources are required") + endif() + + set(sources) + foreach(source IN LISTS ARG_SOURCES) + list(APPEND sources "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${source}") + endforeach() + add_library(${target} STATIC ${sources}) + string(REGEX REPLACE "^tllm_" "tllm::" alias ${target}) + add_library(${alias} ALIAS ${target}) + target_link_libraries(${target} PUBLIC tllm::common_cuda + ${ARG_LINK_LIBRARIES}) + target_include_directories(${target} PRIVATE ${ARG_INCLUDE_DIRECTORIES}) + target_compile_features(${target} PUBLIC cxx_std_20) + target_compile_options( + ${target} PRIVATE $<$:--expt-relaxed-constexpr>) + set_target_properties( + ${target} + PROPERTIES POSITION_INDEPENDENT_CODE ON CUDA_STANDARD 20 + CUDA_STANDARD_REQUIRED ON CUDA_RESOLVE_DEVICE_SYMBOLS ON) + add_cuda_architectures(${target} 89) + + foreach(source_list SRC_CPP SRC_CU MOE_KERNELS_SRC) + list(REMOVE_ITEM ${source_list} ${sources}) + set(${source_list} + ${${source_list}} + PARENT_SCOPE) + endforeach() + set(TLLM_KERNEL_COMPONENT_TARGETS + ${TLLM_KERNEL_COMPONENT_TARGETS} ${target} + PARENT_SCOPE) +endfunction() + +add_tllm_kernel_library(tllm_kernel_logits SOURCES logitsBitmask.cu) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index c0c393a2634a..8faa4b95764d 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -13,7 +13,18 @@ # License for the specific language governing permissions and limitations under # the License. -add_gtest(logitsBitmaskTest logitsBitmaskTest.cpp) +add_tllm_gtest( + logitsBitmaskTest + OWNER + kernel + SOURCES + logitsBitmaskTest.cpp + LINK_LIBRARIES + tllm::kernel_logits + tllm::runtime_buffers + LABELS + "unit;kernels;logits;gpu" + REQUIRES_GPU) add_gtest(cascadeAttentionKernelTest cascadeAttentionKernelTest.cpp) add_gtest(cascadeAttentionNumericsTest cascadeAttentionNumericsTest.cu) From 3a5aefa5077571c625f1ff18772bf3da9bf2d9fe Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:42:11 +0000 Subject: [PATCH 06/37] build: extract the NVFP4 cold-page kernel family Create tllm::kernel_nvfp4_cold_page with explicit ownership of nvfp4ColdPageKernels.cu and its environment/CUDA dependencies. Preserve the existing architecture selection and export the family through the shared-library component loop. Replace the cold-page test's manually assembled production source list with ordinary links to the kernel family and tllm::kv_cache_host_memory. The error, logging, environment, host-memory, and poison implementations now have their production owners instead of being recompiled inside the test. Register the executable with kernel-tests and GPU resource locking. Validation: nvfp4ColdPageKernelsTest compiles and links independently. Its generated graph excludes the full shared library, kernels_src, residual common/runtime libraries, batch manager, executor, and Torch. Test discovery succeeds and the original production-source compilation counts are preserved. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/kernelComponents.cmake | 4 +++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 33 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 473c21c626c5..29fdcd5dfb6b 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -55,3 +55,7 @@ function(add_tllm_kernel_library target) endfunction() add_tllm_kernel_library(tllm_kernel_logits SOURCES logitsBitmask.cu) + +add_tllm_kernel_library( + tllm_kernel_nvfp4_cold_page SOURCES nvfp4ColdPageKernels.cu LINK_LIBRARIES + tllm::common_environment) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 8faa4b95764d..8b74564c0e84 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -113,26 +113,15 @@ add_gtest(sparseKvCacheTest sparseKvCacheTest.cu) add_gtest(prepareCustomMaskTest prepareCustomMaskTest.cpp) add_gtest(fmhaDsv4EpilogueFusionTest fmhaDsv4EpilogueFusionTest.cpp) -set(NVFP4_COLD_PAGE_KERNEL_TEST_SRC - nvfp4ColdPageKernelsTest.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/kernels/nvfp4ColdPageKernels.cu - ${PROJECT_SOURCE_DIR}/tensorrt_llm/batch_manager/kv_cache_manager_v2/utils/hostMem.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/batch_manager/kv_cache_manager_v2/utils/hostMemBacking.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/runtime/moeLoadBalancer/topologyDetector.cpp - # ~HostMem reports a failed cleanup through the poison latch, so this target - # needs the latch itself: NO_TLLM_LINKAGE means nothing else supplies it. - ${PROJECT_SOURCE_DIR}/tensorrt_llm/batch_manager/kv_cache_manager_v2/utils/poison.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/common/assert.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/common/envUtils.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/common/logger.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/common/stringUtils.cpp - ${PROJECT_SOURCE_DIR}/tensorrt_llm/common/tllmException.cpp) -add_gtest(nvfp4ColdPageKernelsTest "${NVFP4_COLD_PAGE_KERNEL_TEST_SRC}" - NO_TLLM_LINKAGE) -target_include_directories( +add_tllm_gtest( nvfp4ColdPageKernelsTest - PRIVATE ${PROJECT_SOURCE_DIR}/tensorrt_llm/batch_manager) -# numa: the backing places pages with mbind and the topology detector reads the -# node layout through libnuma. -target_link_libraries(nvfp4ColdPageKernelsTest PRIVATE CUDA::cudart - CUDA::cuda_driver numa) + OWNER + kernel + SOURCES + nvfp4ColdPageKernelsTest.cpp + LINK_LIBRARIES + tllm::kernel_nvfp4_cold_page + tllm::kv_cache_host_memory + LABELS + "unit;kernels;nvfp4-cold-page;gpu" + REQUIRES_GPU) From d9aa5537f4da8714eceb17decfac2b9c3665dc23 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:55:12 +0000 Subject: [PATCH 07/37] build: extract RoPE and QKV preprocessing kernels Give attention mask construction, decoder metadata, unfused attention and all eleven QKV type instantiations one explicit static-library owner, tllm::kernel_rope. Remove these sources from kernels_src while preserving the shared library's whole-archive exports, CUDA architecture policy and FP16/BF16/FP32, INT8, FP8 and FP4 instantiations. Migrate ropeTest, shiftKCacheKernelTest and sparseKvCacheTest to explicit RoPE and runtime-buffer dependencies. Register them with kernel-tests, GPU labels and the GPU resource lock; sparse cache updates use the same QKV instantiations rather than introducing another production owner. Validation: build and link all three leaf tests in the CUDA 13.4 SM80 configuration; inspect their Ninja graphs to exclude the monolithic library, residual object libraries and Torch. Check that original source compilation counts are preserved and discovered GPU cases retain their resource lock. GPU execution requires hardware unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/kernelComponents.cmake | 20 ++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 39 +++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 29fdcd5dfb6b..a3fc0604a4ce 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -59,3 +59,23 @@ add_tllm_kernel_library(tllm_kernel_logits SOURCES logitsBitmask.cu) add_tllm_kernel_library( tllm_kernel_nvfp4_cold_page SOURCES nvfp4ColdPageKernels.cu LINK_LIBRARIES tllm::common_environment) + +add_tllm_kernel_library( + tllm_kernel_rope + SOURCES + attentionMask.cu + gptKernels.cu + unfusedAttentionKernels.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_bf16_bf16.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_bf16_fp4.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_bf16_fp8.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_bf16_int8.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_float_float.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_float_fp8.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_float_int8.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_half_fp4.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_half_fp8.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_half_half.cu + unfusedAttentionKernels/unfusedAttentionKernels_2_half_int8.cu + LINK_LIBRARIES + tllm::common_environment) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 8b74564c0e84..08533beb58ab 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -50,8 +50,30 @@ if(USING_OSS_CUTLASS_MOE_GEMM) USING_OSS_CUTLASS_MOE_GEMM) endif() -add_gtest(ropeTest ropeTest.cu) -add_gtest(shiftKCacheKernelTest shiftKCacheKernelTest.cu) +add_tllm_gtest( + ropeTest + OWNER + kernel + SOURCES + ropeTest.cu + LINK_LIBRARIES + tllm::kernel_rope + tllm::runtime_buffers + LABELS + "unit;kernels;rope;gpu" + REQUIRES_GPU) +add_tllm_gtest( + shiftKCacheKernelTest + OWNER + kernel + SOURCES + shiftKCacheKernelTest.cu + LINK_LIBRARIES + tllm::kernel_rope + tllm::runtime_buffers + LABELS + "unit;kernels;rope;gpu" + REQUIRES_GPU) add_gtest(smoothQuantKernelTest smoothQuant/smoothQuantKernelTest.cpp) add_gtest(weightOnlyKernelTest weightOnly/weightOnlyKernelTest.cpp) add_gtest(mlaPreprocessTest mlaPreprocessTest.cu) @@ -109,7 +131,18 @@ if(USING_OSS_CUTLASS_MOE_GEMM) add_gtest(moeLoraSlotExpandTest moe/moeLoraSlotExpandTest.cu) endif() -add_gtest(sparseKvCacheTest sparseKvCacheTest.cu) +add_tllm_gtest( + sparseKvCacheTest + OWNER + kernel + SOURCES + sparseKvCacheTest.cu + LINK_LIBRARIES + tllm::kernel_rope + tllm::runtime_buffers + LABELS + "unit;kernels;rope;sparse-kv-cache;gpu" + REQUIRES_GPU) add_gtest(prepareCustomMaskTest prepareCustomMaskTest.cpp) add_gtest(fmhaDsv4EpilogueFusionTest fmhaDsv4EpilogueFusionTest.cpp) From 7e6603426e0d59d7155e4fafc50a5043e0e463e6 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:58:31 +0000 Subject: [PATCH 08/37] build: extract sparse-attention page-gather kernels Move sparseAttentionKernels.cu from kernels_src into the explicitly sourced tllm::kernel_sparse_attention static library. Keep production exports through the shared-library component list and inherit only common CUDA utilities, preserving the existing architecture policy. Migrate sparseAttentionKernelsTest to this library and runtime buffers, register it under kernel-tests and assign sparse-attention/GPU labels with a GPU resource lock. A page-gather leaf build no longer pulls in RoPE instantiations, attention backends or the full product library. Validation: build and link sparseAttentionKernelsTest with CUDA 13.4 and SM80 in both the product configuration and a separate clean component-only build (no libtensorrt_llm.so produced); check its Ninja dependency graph, original production-source compilation counts and discovered GPU scheduling properties. GPU cases are discoverable but cannot execute without GPU hardware. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 3 +++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index a3fc0604a4ce..f0bc438d302f 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -79,3 +79,6 @@ add_tllm_kernel_library( unfusedAttentionKernels/unfusedAttentionKernels_2_half_int8.cu LINK_LIBRARIES tllm::common_environment) + +add_tllm_kernel_library(tllm_kernel_sparse_attention SOURCES + sparseAttentionKernels.cu) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 08533beb58ab..2a465bed38d7 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -77,7 +77,18 @@ add_tllm_gtest( add_gtest(smoothQuantKernelTest smoothQuant/smoothQuantKernelTest.cpp) add_gtest(weightOnlyKernelTest weightOnly/weightOnlyKernelTest.cpp) add_gtest(mlaPreprocessTest mlaPreprocessTest.cu) -add_gtest(sparseAttentionKernelsTest sparseAttentionKernelsTest.cpp) +add_tllm_gtest( + sparseAttentionKernelsTest + OWNER + kernel + SOURCES + sparseAttentionKernelsTest.cpp + LINK_LIBRARIES + tllm::kernel_sparse_attention + tllm::runtime_buffers + LABELS + "unit;kernels;sparse-attention;gpu" + REQUIRES_GPU) add_gtest(cudaCoreGemmKernelTest cudaCoreGemm/cudaCoreGemmKernelTest.cpp) From 807271904bdbbf73e9e031cdddfeeafc41882952 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:01:24 +0000 Subject: [PATCH 09/37] build: extract MLA preprocessing kernels Assign mlaKernels.cu to the explicitly sourced tllm::kernel_mla static library instead of kernels_src. Declare the environment and common CUDA dependencies used by MLA launchers, retain existing type instantiations and architecture settings, and preserve all shared-library exports. Make mlaPreprocessTest a component-local kernel test linking only MLA preprocessing and runtime buffers. Register GPU labels and resource locking through add_tllm_gtest and include it in kernel-tests. Building this paged-KV preprocessing test no longer builds generated FMHA, FlashMLA, CUTLASS GEMM or the TensorRT-LLM shared library. Validation: build and link the leaf with CUDA 13.4/SM80; verify its Ninja graph excludes residual component objects, Torch and the monolith, production source ownership is unchanged, and discovery retains GPU scheduling properties. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 3 +++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index f0bc438d302f..a3c9dd62f267 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -82,3 +82,6 @@ add_tllm_kernel_library( add_tllm_kernel_library(tllm_kernel_sparse_attention SOURCES sparseAttentionKernels.cu) + +add_tllm_kernel_library(tllm_kernel_mla SOURCES mlaKernels.cu LINK_LIBRARIES + tllm::common_environment) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 2a465bed38d7..247c05b45a2a 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -76,7 +76,18 @@ add_tllm_gtest( REQUIRES_GPU) add_gtest(smoothQuantKernelTest smoothQuant/smoothQuantKernelTest.cpp) add_gtest(weightOnlyKernelTest weightOnly/weightOnlyKernelTest.cpp) -add_gtest(mlaPreprocessTest mlaPreprocessTest.cu) +add_tllm_gtest( + mlaPreprocessTest + OWNER + kernel + SOURCES + mlaPreprocessTest.cu + LINK_LIBRARIES + tllm::kernel_mla + tllm::runtime_buffers + LABELS + "unit;kernels;mla;gpu" + REQUIRES_GPU) add_tllm_gtest( sparseAttentionKernelsTest OWNER From 951f4809bbcc957905e5867a009a74f9f78f2ca0 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:03:51 +0000 Subject: [PATCH 10/37] build: extract MLA chunked-prefill kernels Move mlaChunkedPrefill.cu into the explicitly sourced static library tllm::kernel_mla_chunked_prefill. Declare its CUTLASS header include path without pulling any CUTLASS GEMM implementation into the leaf. Preserve the shared-library exports and existing CUDA architecture policy. Migrate mlaChunkedPrefillTest to the chunked-prefill component and runtime buffers, with kernel aggregate registration, GPU labels and the GPU resource lock. This separates chunked KV loading and softmax merging from MLA RoPE preprocessing and generated attention backends. Validation: build and link the test with CUDA 13.4/SM80; check the Ninja graph excludes the monolith, Torch and residual object targets, preserve production source compilation counts, and verify discovered GPU scheduling properties. GPU execution requires hardware unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 4 ++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index a3c9dd62f267..7e19401697b9 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -85,3 +85,7 @@ add_tllm_kernel_library(tllm_kernel_sparse_attention SOURCES add_tllm_kernel_library(tllm_kernel_mla SOURCES mlaKernels.cu LINK_LIBRARIES tllm::common_environment) + +add_tllm_kernel_library( + tllm_kernel_mla_chunked_prefill SOURCES mlaChunkedPrefill.cu + INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 247c05b45a2a..9faf4c1dac80 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -103,7 +103,18 @@ add_tllm_gtest( add_gtest(cudaCoreGemmKernelTest cudaCoreGemm/cudaCoreGemmKernelTest.cpp) -add_gtest(mlaChunkedPrefillTest mlaChunkedPrefillTest.cu) +add_tllm_gtest( + mlaChunkedPrefillTest + OWNER + kernel + SOURCES + mlaChunkedPrefillTest.cu + LINK_LIBRARIES + tllm::kernel_mla_chunked_prefill + tllm::runtime_buffers + LABELS + "unit;kernels;mla-chunked-prefill;gpu" + REQUIRES_GPU) add_gtest(fusedMoeCommKernelTest moe/fusedMoeCommKernelTest.cpp) From f1e51f8c945cb53f570b47e3b5ade98f9b72fd89 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:07:26 +0000 Subject: [PATCH 11/37] build: extract fused MoE communication kernels Give fusedMoeCommKernels.cu an explicit static-library owner, tllm::kernel_moe_communication. Remove it from the residual MoE source list and preserve shared-library exports and CUDA architecture settings. Declare common CUDA and environment dependencies for its PDL launchers and CUDA::cuda_driver for workspace initialization via cuMemsetD32. Migrate fusedMoeCommKernelTest to explicit fused-communication and thread dependencies without runtime buffers, GEMM backends or full-stack linkage. Register the test under kernel-tests with MoE communication and GPU labels and a GPU resource lock. Other communication implementations remain in their existing owners until their own callers need extraction. Validation: compile and link the leaf with CUDA 13.4/SM80, verify its component-local Ninja graph and preserved source ownership, and inspect discovered GPU resource locks. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 5 +++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 7e19401697b9..0a3c6db61759 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -89,3 +89,8 @@ add_tllm_kernel_library(tllm_kernel_mla SOURCES mlaKernels.cu LINK_LIBRARIES add_tllm_kernel_library( tllm_kernel_mla_chunked_prefill SOURCES mlaChunkedPrefill.cu INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) + +add_tllm_kernel_library( + tllm_kernel_moe_communication SOURCES + moe/communication/fusedMoeCommKernels.cu LINK_LIBRARIES + tllm::common_environment CUDA::cuda_driver) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 9faf4c1dac80..176d575e1f07 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -116,7 +116,18 @@ add_tllm_gtest( "unit;kernels;mla-chunked-prefill;gpu" REQUIRES_GPU) -add_gtest(fusedMoeCommKernelTest moe/fusedMoeCommKernelTest.cpp) +add_tllm_gtest( + fusedMoeCommKernelTest + OWNER + kernel + SOURCES + moe/fusedMoeCommKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_moe_communication + Threads::Threads + LABELS + "unit;kernels;moe-communication;gpu" + REQUIRES_GPU) add_gtest( gemmSwigluRunnerTest From 34c834b844306c10381d3e704258dd4c9a5bca55 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:09:45 +0000 Subject: [PATCH 12/37] build: extract MoE load-balancing kernels Assign moe/loadBalance/moeLoadBalanceKernels.cu to the focused static library tllm::kernel_moe_load_balance, removing it from residual MoE sources while retaining shared-library exports and CUDA architectures. Declare common CUDA and environment utilities used by its cooperative and PDL launchers. Migrate moeLoadBalanceKernelTest to the load-balancing component and Threads::Threads. Its signal and expert-load tests allocate through CUDA directly and do not need runtime-buffer, communication or GEMM libraries. Register kernel aggregate ownership, GPU labels and a GPU resource lock. Validation: build and link with CUDA 13.4/SM80; verify the leaf Ninja graph, unchanged production-source ownership and discovered GPU resource locks. GPU execution requires hardware unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 4 ++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 0a3c6db61759..8707540ffccd 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -94,3 +94,7 @@ add_tllm_kernel_library( tllm_kernel_moe_communication SOURCES moe/communication/fusedMoeCommKernels.cu LINK_LIBRARIES tllm::common_environment CUDA::cuda_driver) + +add_tllm_kernel_library( + tllm_kernel_moe_load_balance SOURCES moe/loadBalance/moeLoadBalanceKernels.cu + LINK_LIBRARIES tllm::common_environment) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 176d575e1f07..eb59b2651b5c 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -167,7 +167,18 @@ target_link_libraries(routingKernelsTest PRIVATE Python3::Python) add_gtest(blockScaleMoeActivationTest moe/blockScaleMoeActivationTest.cu) add_gtest(blockScaleMoeFinalizeTest moe/blockScaleMoeFinalizeTest.cu) -add_gtest(moeLoadBalanceKernelTest moe/moeLoadBalanceKernelTest.cpp) +add_tllm_gtest( + moeLoadBalanceKernelTest + OWNER + kernel + SOURCES + moe/moeLoadBalanceKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_moe_load_balance + Threads::Threads + LABELS + "unit;kernels;moe-load-balance;gpu" + REQUIRES_GPU) if(USING_OSS_CUTLASS_MOE_GEMM) add_gtest(moeLoraPointerExpandTest moe/moeLoraPointerExpandTest.cu) From 4c244cbc0c687a990be3b3645526ce02441b48df Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:11:56 +0000 Subject: [PATCH 13/37] build: extract MoE LoRA preparation kernels Create tllm::kernel_moe_lora with explicit pointer-expansion, problem-builder and slot-expansion CUDA sources. Remove those sources from the CUTLASS MoE launcher object library and link the existing MoE GEMM backend to the new owner. Preserve OSS-MoE gating, CUDA architectures and shared-library exports; expose only CUTLASS headers needed by problem-size declarations. Migrate moeLoraPointerExpandTest, moeLoraProblemBuilderTest and moeLoraSlotExpandTest to the focused component. Their direct CUDA allocations need neither runtime buffers nor the full MoE GEMM backend. Register all three with kernel-tests, MoE LoRA/GPU labels and GPU locks. Validation: build and link all three leaves with CUDA 13.4/SM80; inspect their graphs to exclude the monolith, residual objects and Torch; verify original kernel/backend compilation counts and discovered GPU scheduling properties. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 11 ++++-- .../kernels/kernelComponents.cmake | 8 +++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 36 +++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index 20aedcd1e321..15e51ff79920 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -163,7 +163,8 @@ file(GLOB_RECURSE MIXED_SRC_CU fpA_intB_gemm/*.cu) # Get the sources for MOE Grouped GEMM launchers. They live in the MoE domain # directory; the targets stay here, next to the CUTLASS instantiation generator # and the helpers (process_target, add_instantiations) they use. -set(MOE_CUTLASS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../moe/cutlass) +get_filename_component(MOE_CUTLASS_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/../moe/cutlass" ABSOLUTE) file(GLOB_RECURSE GROUPED_SRC_CPP ${MOE_CUTLASS_DIR}/*.cpp) file(GLOB_RECURSE GROUPED_SRC_CU ${MOE_CUTLASS_DIR}/*.cu) @@ -242,6 +243,10 @@ endif() if(USING_OSS_CUTLASS_MOE_GEMM) file(GLOB MOE_GEMM_SRC_CU "${MOE_CUTLASS_DIR}/*.cu") + list( + REMOVE_ITEM MOE_GEMM_SRC_CU "${MOE_CUTLASS_DIR}/moe_lora_pointer_expand.cu" + "${MOE_CUTLASS_DIR}/moe_lora_problem_builder.cu" + "${MOE_CUTLASS_DIR}/moe_lora_slot_expand.cu") set(MOE_GEMM_SRC_CU_LAUNCHER ${MOE_GEMM_SRC_CU}) list(FILTER MOE_GEMM_SRC_CU_LAUNCHER EXCLUDE REGEX ".*moe_gemm_kernels_.*") list(FILTER MOE_GEMM_SRC_CU INCLUDE REGEX ".*moe_gemm_kernels_.*") @@ -276,8 +281,8 @@ if(USING_OSS_CUTLASS_MOE_GEMM) add_instantiations(moe_gemm_src ${INSTANTIATION_GENERATION_DIR}/gemm_grouped) target_link_libraries( - moe_gemm_src PRIVATE _moe_gemm_launcher _moe_gemm_hopper_fp4 _moe_gemm_fp4 - _moe_gemm_fp8) + moe_gemm_src PRIVATE tllm::kernel_moe_lora _moe_gemm_launcher + _moe_gemm_hopper_fp4 _moe_gemm_fp4 _moe_gemm_fp8) target_include_directories( moe_gemm_src PUBLIC ${PROJECT_SOURCE_DIR}/tensorrt_llm/cutlass_extensions/include) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 8707540ffccd..41cc7af482ec 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -98,3 +98,11 @@ add_tllm_kernel_library( add_tllm_kernel_library( tllm_kernel_moe_load_balance SOURCES moe/loadBalance/moeLoadBalanceKernels.cu LINK_LIBRARIES tllm::common_environment) + +if(USING_OSS_CUTLASS_MOE_GEMM) + add_tllm_kernel_library( + tllm_kernel_moe_lora SOURCES moe/cutlass/moe_lora_pointer_expand.cu + moe/cutlass/moe_lora_problem_builder.cu moe/cutlass/moe_lora_slot_expand.cu) + target_include_directories( + tllm_kernel_moe_lora PUBLIC ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) +endif() diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index eb59b2651b5c..e8df03894552 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -181,9 +181,39 @@ add_tllm_gtest( REQUIRES_GPU) if(USING_OSS_CUTLASS_MOE_GEMM) - add_gtest(moeLoraPointerExpandTest moe/moeLoraPointerExpandTest.cu) - add_gtest(moeLoraProblemBuilderTest moe/moeLoraProblemBuilderTest.cu) - add_gtest(moeLoraSlotExpandTest moe/moeLoraSlotExpandTest.cu) + add_tllm_gtest( + moeLoraPointerExpandTest + OWNER + kernel + SOURCES + moe/moeLoraPointerExpandTest.cu + LINK_LIBRARIES + tllm::kernel_moe_lora + LABELS + "unit;kernels;moe-lora;gpu" + REQUIRES_GPU) + add_tllm_gtest( + moeLoraProblemBuilderTest + OWNER + kernel + SOURCES + moe/moeLoraProblemBuilderTest.cu + LINK_LIBRARIES + tllm::kernel_moe_lora + LABELS + "unit;kernels;moe-lora;gpu" + REQUIRES_GPU) + add_tllm_gtest( + moeLoraSlotExpandTest + OWNER + kernel + SOURCES + moe/moeLoraSlotExpandTest.cu + LINK_LIBRARIES + tllm::kernel_moe_lora + LABELS + "unit;kernels;moe-lora;gpu" + REQUIRES_GPU) endif() add_tllm_gtest( From 15b8b020fa928e691750c187b40421012ab9172d Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:14:08 +0000 Subject: [PATCH 14/37] build: extract custom attention-mask preparation Move prepareCustomMask.cu from the generated FMHA object target into tllm::kernel_attention_mask with explicit source ownership. Link the FMHA backend to the new component, preserve shared-library exports, and declare the FMHA header interface and CUTLASS header requirements without inheriting generated kernels or prebuilt FMHA implementation. Migrate prepareCustomMaskTest to mask preparation and runtime buffers. Register it with kernel-tests, attention-mask/GPU labels and a GPU lock. Mask-format leaf builds now avoid generated FMHA, GEMM backends, Torch and the monolithic TensorRT-LLM shared library. Validation: build and link the leaf with CUDA 13.4/SM80; verify its Ninja graph excludes residual object libraries and the full stack, preserve production/backend source compilation counts, and inspect discovered GPU scheduling properties. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 6 ++++++ .../kernels/trtllmGenKernels/fmha/CMakeLists.txt | 4 +++- cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 41cc7af482ec..2d17d6b922b9 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -106,3 +106,9 @@ if(USING_OSS_CUTLASS_MOE_GEMM) target_include_directories( tllm_kernel_moe_lora PUBLIC ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) endif() + +add_tllm_kernel_library( + tllm_kernel_attention_mask SOURCES trtllmGenKernels/fmha/prepareCustomMask.cu + LINK_LIBRARIES trtllm_gen_fmha_interface) +target_include_directories(tllm_kernel_attention_mask + PUBLIC ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) diff --git a/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt b/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt index 5731ed4f0549..c251d3b9f613 100644 --- a/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt @@ -48,6 +48,7 @@ configure_file( file(GLOB_RECURSE SRC_CPP *.cpp) file(GLOB_RECURSE SRC_CU *.cu) +list(REMOVE_ITEM SRC_CU "${CMAKE_CURRENT_SOURCE_DIR}/prepareCustomMask.cu") # Archs listed here are pruned when the build does not enable them. Sm100f has # no context FMHA kernel, so Rubin needs the prebuilt Sm107a cubins kept @@ -67,7 +68,8 @@ target_include_directories( add_library(trtllm_gen_fmha OBJECT ${SRC_CPP} ${SRC_CU}) set_property(TARGET trtllm_gen_fmha PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET trtllm_gen_fmha PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) -target_link_libraries(trtllm_gen_fmha PUBLIC trtllm_gen_fmha_interface) +target_link_libraries(trtllm_gen_fmha PUBLIC trtllm_gen_fmha_interface + tllm::kernel_attention_mask) target_include_directories( trtllm_gen_fmha PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/trtllmGen_fmha_export) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index e8df03894552..33203b53a14f 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -228,7 +228,18 @@ add_tllm_gtest( LABELS "unit;kernels;rope;sparse-kv-cache;gpu" REQUIRES_GPU) -add_gtest(prepareCustomMaskTest prepareCustomMaskTest.cpp) +add_tllm_gtest( + prepareCustomMaskTest + OWNER + kernel + SOURCES + prepareCustomMaskTest.cpp + LINK_LIBRARIES + tllm::kernel_attention_mask + tllm::runtime_buffers + LABELS + "unit;kernels;attention-mask;gpu" + REQUIRES_GPU) add_gtest(fmhaDsv4EpilogueFusionTest fmhaDsv4EpilogueFusionTest.cpp) add_tllm_gtest( From ea56f20aa5a8c17b5cb0f603a13683ea00c32a61 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:18:26 +0000 Subject: [PATCH 15/37] build: extract CUDA core GEMM kernels Move weightOnlyBatchedGemv/cudaCoreGemm.cu from kernels_src into the explicit static library tllm::kernel_cuda_core_gemm, preserving product exports, type instantiations and CUDA architectures. Declare the environment utilities used by PDL dispatch and a reusable CUTLASS header interface covering vendor headers, utility headers and local extensions. Migrate cudaCoreGemmKernelTest to this component and CUDA::cublasLt for its reference implementation. Its direct CUDA allocations do not need runtime buffers or CUTLASS GEMM binaries. Register kernel aggregate ownership, CUDA core GEMM/GPU labels and the GPU resource lock. Validation: build and link with CUDA 13.4/SM80, verify the leaf graph excludes the full stack and residual objects, check unchanged source ownership and discovered GPU locks. GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 13 +++++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 2d17d6b922b9..f13bd8abf4ca 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -15,6 +15,15 @@ # the License. # +add_library(tllm_kernel_cutlass_headers INTERFACE) +add_library(tllm::kernel_cutlass_headers ALIAS tllm_kernel_cutlass_headers) +target_include_directories( + tllm_kernel_cutlass_headers + INTERFACE ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include + ${CMAKE_BINARY_DIR}/_deps/cutlass-src/tools/util/include + ${CMAKE_CURRENT_LIST_DIR}/../cutlass_extensions/include) +target_link_libraries(tllm_kernel_cutlass_headers INTERFACE tllm::common_cuda) + function(add_tllm_kernel_library target) set(multi_value_args SOURCES LINK_LIBRARIES INCLUDE_DIRECTORIES) cmake_parse_arguments(PARSE_ARGV 1 ARG "" "" "${multi_value_args}") @@ -112,3 +121,7 @@ add_tllm_kernel_library( LINK_LIBRARIES trtllm_gen_fmha_interface) target_include_directories(tllm_kernel_attention_mask PUBLIC ${CMAKE_BINARY_DIR}/_deps/cutlass-src/include) + +add_tllm_kernel_library( + tllm_kernel_cuda_core_gemm SOURCES weightOnlyBatchedGemv/cudaCoreGemm.cu + LINK_LIBRARIES tllm::common_environment tllm::kernel_cutlass_headers) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 33203b53a14f..e68eb1d938ac 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -101,7 +101,18 @@ add_tllm_gtest( "unit;kernels;sparse-attention;gpu" REQUIRES_GPU) -add_gtest(cudaCoreGemmKernelTest cudaCoreGemm/cudaCoreGemmKernelTest.cpp) +add_tllm_gtest( + cudaCoreGemmKernelTest + OWNER + kernel + SOURCES + cudaCoreGemm/cudaCoreGemmKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_cuda_core_gemm + CUDA::cublasLt + LABELS + "unit;kernels;cuda-core-gemm;gpu" + REQUIRES_GPU) add_tllm_gtest( mlaChunkedPrefillTest From 5c75e411a86b5fe31df07918d8c5bfa2544eeab2 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:20:29 +0000 Subject: [PATCH 16/37] build: extract shared CUTLASS GEMM host utilities Give cutlass_heuristic.cpp and cutlass_preprocessors.cpp one explicit static-library owner, tllm::kernel_gemm_utilities. These host utilities provide tactic configuration and weight layout preprocessing shared by gated, INT8, weight-only and MoE GEMM implementations. Declare their CUTLASS header/common CUDA requirements without linking GEMM kernels. Remove both files from cutlass_src and make that compatibility target link the focused utility component. Preserve all production exports through the shared-library component list. This prepares independent GEMM-family migrations without duplicating utility compilation or forcing their tests through the broad CUTLASS target. Validation: build the utility library with the CUDA 13.4/SM80 toolchain, verify its Ninja graph excludes GEMM implementation families, residual objects, Torch and the monolith, and check that all original production and generated kernel source compilation counts remain unchanged. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt | 3 +++ cpp/tensorrt_llm/kernels/kernelComponents.cmake | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index 15e51ff79920..42c48c11adc0 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -184,6 +184,8 @@ file(GLOB_RECURSE ARGEMM_SRC_CU allreduce_gemm/*.cu) file(GLOB_RECURSE SRC_CPP *.cpp) file(GLOB_RECURSE SRC_CU *.cu) set(ALL_SRCS ${SRC_CPP};${SRC_CU}) +list(REMOVE_ITEM ALL_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/cutlass_heuristic.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/cutlass_preprocessors.cpp") list(FILTER ALL_SRCS EXCLUDE REGEX "fpA_intB_gemm/.*") list(FILTER ALL_SRCS EXCLUDE REGEX "fp8_rowwise_gemm/.*") list(FILTER ALL_SRCS EXCLUDE REGEX "fp8_blockscale_gemm/.*") @@ -207,6 +209,7 @@ message(VERBOSE "ARgemm srcs ${ARGEMM_SRC_CU}") message(VERBOSE "All srcs ${ALL_SRCS}") add_library(cutlass_src STATIC ${ALL_SRCS}) +target_link_libraries(cutlass_src PUBLIC tllm::kernel_gemm_utilities) add_library(fpA_intB_gemm_src STATIC ${MIXED_SRC_CPP} ${MIXED_SRC_CU}) add_cuda_architectures(fpA_intB_gemm_src 89) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index f13bd8abf4ca..e0d89f973a3d 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -125,3 +125,8 @@ target_include_directories(tllm_kernel_attention_mask add_tllm_kernel_library( tllm_kernel_cuda_core_gemm SOURCES weightOnlyBatchedGemv/cudaCoreGemm.cu LINK_LIBRARIES tllm::common_environment tllm::kernel_cutlass_headers) + +add_tllm_kernel_library( + tllm_kernel_gemm_utilities SOURCES cutlass_kernels/cutlass_heuristic.cpp + cutlass_kernels/cutlass_preprocessors.cpp LINK_LIBRARIES + tllm::kernel_cutlass_headers) From 96c293114f9e0462558a1fce7330d2a6f1bf9429 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:23:20 +0000 Subject: [PATCH 17/37] build: migrate fused gated GEMM tests to focused targets Expose the existing single-source SM90 gated GEMM static library as tllm::kernel_gated_gemm and declare its shared GEMM utility dependencies. Preserve its architecture scoping and retain production symbols through the shared-library component list. Link gemmSwigluRunnerTest explicitly to that family instead of the product library; remove the obsolete extra production-source argument ignored by the legacy helper. Build the header-defined gemmSwigluKernelTestSm90Fp8 executable with CUTLASS headers, common CUDA utilities and GoogleTest assertions only. Register its standalone main directly as one CTest case, avoiding GoogleTest discovery running its CUDA workload during enumeration. Keep both custom mains, device-symbol resolution, Hopper feature gating and compiler options, and assign kernel aggregate ownership and GPU locks. Validation: build and link both targets with CUDA 13.4/SM80, inspect component-local Ninja graphs and preserved production-source ownership, and enumerate the runner case and standalone executable without GPU execution. Both cases carry GPU labels and resource locks. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 2 ++ .../kernels/kernelComponents.cmake | 2 ++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index 42c48c11adc0..7ef9fb922ed8 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -226,6 +226,8 @@ set_cuda_architectures(fp8_blockscale_gemm_src ${CUTLASS_COMMON_ARCHS}) set(GEMM_SWIGLU_SM90_SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/fused_gated_gemm/gemm_swiglu_e4m3.cu) add_library(gemm_swiglu_sm90_src STATIC ${GEMM_SWIGLU_SM90_SRC_CU}) +add_library(tllm::kernel_gated_gemm ALIAS gemm_swiglu_sm90_src) +target_link_libraries(gemm_swiglu_sm90_src PUBLIC tllm::kernel_gemm_utilities) set_cuda_architectures(gemm_swiglu_sm90_src 90) if(USING_OSS_CUTLASS_LOW_LATENCY_GEMM) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index e0d89f973a3d..1b9bb0e15963 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -130,3 +130,5 @@ add_tllm_kernel_library( tllm_kernel_gemm_utilities SOURCES cutlass_kernels/cutlass_heuristic.cpp cutlass_kernels/cutlass_preprocessors.cpp LINK_LIBRARIES tllm::kernel_cutlass_headers) + +list(APPEND TLLM_KERNEL_COMPONENT_TARGETS gemm_swiglu_sm90_src) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index e68eb1d938ac..740c717d65a9 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -140,14 +140,31 @@ add_tllm_gtest( "unit;kernels;moe-communication;gpu" REQUIRES_GPU) -add_gtest( +add_tllm_gtest( gemmSwigluRunnerTest + OWNER + kernel + SOURCES fused_gated_gemm/gemmSwigluRunnerTest.cu - ${PROJECT_SOURCE_DIR}/tensorrt_llm/cutlass_extensions/kernels/fused_gated_gemm/gemm_swiglu_e4m3.cu - NO_GTEST_MAIN) -add_gtest(gemmSwigluKernelTestSm90Fp8 - fused_gated_gemm/gemmSwigluKernelTestSm90Fp8.cu NO_GTEST_MAIN - NO_TLLM_LINKAGE) + LINK_LIBRARIES + tllm::kernel_gated_gemm + LABELS + "unit;kernels;gated-gemm;gpu" + NO_GTEST_MAIN + REQUIRES_GPU) + +add_executable(gemmSwigluKernelTestSm90Fp8 EXCLUDE_FROM_ALL + fused_gated_gemm/gemmSwigluKernelTestSm90Fp8.cu) +target_link_libraries(gemmSwigluKernelTestSm90Fp8 + PRIVATE gtest tllm::kernel_cutlass_headers) +target_compile_features(gemmSwigluKernelTestSm90Fp8 PRIVATE cxx_std_20) +add_test(NAME gemmSwigluKernelTestSm90Fp8 COMMAND gemmSwigluKernelTestSm90Fp8) +set_tests_properties( + gemmSwigluKernelTestSm90Fp8 + PROPERTIES ENVIRONMENT "CUDA_MODULE_LOADING=LAZY" LABELS + "unit;kernels;gated-gemm;gpu" RESOURCE_LOCK gpu) +add_dependencies(kernel-tests gemmSwigluKernelTestSm90Fp8) +add_dependencies(google-tests gemmSwigluKernelTestSm90Fp8) foreach(target_name gemmSwigluRunnerTest;gemmSwigluKernelTestSm90Fp8) set_property(TARGET ${target_name} PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) From c09d8771859ce5b2522c39e8235b1a7ebdeeb914 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:27:22 +0000 Subject: [PATCH 18/37] build: extract SmoothQuant and INT8 GEMM kernels Create explicitly sourced static libraries for int8SQ.cu and the four BF16/FP16/FP32/INT32 CUTLASS INT8 GEMM instantiations. Keep the root GEMV and CUTLASS backend architecture policies separate, declare header and GEMM utility dependencies, and preserve production exports. Remove the INT8 sources from cutlass_src, which forwards its extracted components through an interface when no residual implementation remains. Migrate smoothQuantKernelTest to tllm::kernel_smooth_quant and tllm::kernel_int8_gemm, explicitly naming the implementation under test and its reference backend. Remove unnecessary runtime-buffer and full product linkage, and register kernel ownership, GPU labels and locking. Validation: build and link with CUDA 13.4/SM80; inspect the leaf graph for prohibited monolithic and residual dependencies, check all original production/generated source compilation counts, and verify discovered GPU properties. GPU execution is unavailable on this host. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 18 ++++++++++++++++-- .../kernels/kernelComponents.cmake | 17 +++++++++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index 7ef9fb922ed8..d3b1726bbe08 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -184,6 +184,13 @@ file(GLOB_RECURSE ARGEMM_SRC_CU allreduce_gemm/*.cu) file(GLOB_RECURSE SRC_CPP *.cpp) file(GLOB_RECURSE SRC_CU *.cu) set(ALL_SRCS ${SRC_CPP};${SRC_CU}) +list( + REMOVE_ITEM + ALL_SRCS + "${CMAKE_CURRENT_SOURCE_DIR}/int8_gemm/int8_gemm_bf16.cu" + "${CMAKE_CURRENT_SOURCE_DIR}/int8_gemm/int8_gemm_fp16.cu" + "${CMAKE_CURRENT_SOURCE_DIR}/int8_gemm/int8_gemm_fp32.cu" + "${CMAKE_CURRENT_SOURCE_DIR}/int8_gemm/int8_gemm_int32.cu") list(REMOVE_ITEM ALL_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/cutlass_heuristic.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cutlass_preprocessors.cpp") list(FILTER ALL_SRCS EXCLUDE REGEX "fpA_intB_gemm/.*") @@ -208,8 +215,15 @@ message(VERBOSE "FP4 srcs ${FP4_SRC_CU} ${FP4_CU_INSTANTIATIONS}") message(VERBOSE "ARgemm srcs ${ARGEMM_SRC_CU}") message(VERBOSE "All srcs ${ALL_SRCS}") -add_library(cutlass_src STATIC ${ALL_SRCS}) -target_link_libraries(cutlass_src PUBLIC tllm::kernel_gemm_utilities) +if(ALL_SRCS) + add_library(cutlass_src STATIC ${ALL_SRCS}) + target_link_libraries(cutlass_src PUBLIC tllm::kernel_gemm_utilities + tllm::kernel_int8_gemm) +else() + add_library(cutlass_src INTERFACE) + target_link_libraries(cutlass_src INTERFACE tllm::kernel_gemm_utilities + tllm::kernel_int8_gemm) +endif() add_library(fpA_intB_gemm_src STATIC ${MIXED_SRC_CPP} ${MIXED_SRC_CU}) add_cuda_architectures(fpA_intB_gemm_src 89) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 1b9bb0e15963..98f65024b84c 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -132,3 +132,20 @@ add_tllm_kernel_library( tllm::kernel_cutlass_headers) list(APPEND TLLM_KERNEL_COMPONENT_TARGETS gemm_swiglu_sm90_src) + +add_tllm_kernel_library( + tllm_kernel_int8_gemm + SOURCES + cutlass_kernels/int8_gemm/int8_gemm_bf16.cu + cutlass_kernels/int8_gemm/int8_gemm_fp16.cu + cutlass_kernels/int8_gemm/int8_gemm_fp32.cu + cutlass_kernels/int8_gemm/int8_gemm_int32.cu + LINK_LIBRARIES + tllm::kernel_gemm_utilities) + +add_tllm_kernel_library( + tllm_kernel_smooth_quant SOURCES weightOnlyBatchedGemv/int8SQ.cu + LINK_LIBRARIES tllm::kernel_cutlass_headers) + +set_property(TARGET tllm_kernel_int8_gemm + PROPERTY CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 740c717d65a9..51d356dcf78a 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -74,7 +74,18 @@ add_tllm_gtest( LABELS "unit;kernels;rope;gpu" REQUIRES_GPU) -add_gtest(smoothQuantKernelTest smoothQuant/smoothQuantKernelTest.cpp) +add_tllm_gtest( + smoothQuantKernelTest + OWNER + kernel + SOURCES + smoothQuant/smoothQuantKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_smooth_quant + tllm::kernel_int8_gemm + LABELS + "unit;kernels;smooth-quant;gpu" + REQUIRES_GPU) add_gtest(weightOnlyKernelTest weightOnly/weightOnlyKernelTest.cpp) add_tllm_gtest( mlaPreprocessTest From 9f70a7a7bff6405e45a4af36ad515408a7e7e603 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:31:30 +0000 Subject: [PATCH 19/37] build: extract weight-only GEMV kernels and migrate their test Create tllm::kernel_weight_only with explicit pre-quantization scaling and all FP16/BF16 INT4/INT8, per-channel/groupwise and layout-specific GEMV instantiation sources. Remove them from kernels_src, declare CUTLASS headers and environment utilities, and preserve architectures and shared library exports without duplicating any production translation unit. Expose the existing focused mixed-input CUTLASS GEMM backend as tllm::kernel_weight_only_gemm and declare its host GEMM utility/environment dependencies. Migrate weightOnlyKernelTest to the GEMV implementation and this reference backend, with kernel aggregate ownership and GPU locking. Its direct CUDA allocations do not require runtime-buffer linkage. Validation: build and link the leaf with CUDA 13.4/SM80, inspect its component-only graph and preserved source compilation counts, and verify discovered GPU labels/resource locks. GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 3 ++ .../kernels/kernelComponents.cmake | 32 +++++++++++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 +++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index d3b1726bbe08..1fc95c08adfc 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -226,6 +226,9 @@ else() endif() add_library(fpA_intB_gemm_src STATIC ${MIXED_SRC_CPP} ${MIXED_SRC_CU}) +add_library(tllm::kernel_weight_only_gemm ALIAS fpA_intB_gemm_src) +target_link_libraries(fpA_intB_gemm_src PUBLIC tllm::kernel_gemm_utilities + tllm::common_environment) add_cuda_architectures(fpA_intB_gemm_src 89) add_instantiations(fpA_intB_gemm_src ${INSTANTIATION_GENERATION_DIR}/gemm) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 98f65024b84c..d30107581c47 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -149,3 +149,35 @@ add_tllm_kernel_library( set_property(TARGET tllm_kernel_int8_gemm PROPERTY CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") + +add_tllm_kernel_library( + tllm_kernel_weight_only + SOURCES + preQuantScaleKernel.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4PerChannelColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4PerChannelColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int4PerChannelColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8GroupwiseColumnMajoInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8GroupwiseColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8GroupwiseColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8PerChannelColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8PerChannelColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherBf16Int8PerChannelColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4GroupwiseColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4GroupwiseColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4GroupwiseColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4PerChannelColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4PerChannelColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int4PerChannelColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8GroupwiseColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8GroupwiseColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8GroupwiseColumnMajorInterleavedTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8PerChannelColumnMajorFalse.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8PerChannelColumnMajorInterleavedForHopperTrue.cu + weightOnlyBatchedGemv/kernelDispatcherFp16Int8PerChannelColumnMajorInterleavedTrue.cu + LINK_LIBRARIES + tllm::kernel_cutlass_headers + tllm::common_environment) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 51d356dcf78a..dd006bba2708 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -86,7 +86,18 @@ add_tllm_gtest( LABELS "unit;kernels;smooth-quant;gpu" REQUIRES_GPU) -add_gtest(weightOnlyKernelTest weightOnly/weightOnlyKernelTest.cpp) +add_tllm_gtest( + weightOnlyKernelTest + OWNER + kernel + SOURCES + weightOnly/weightOnlyKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_weight_only + tllm::kernel_weight_only_gemm + LABELS + "unit;kernels;weight-only;gpu" + REQUIRES_GPU) add_tllm_gtest( mlaPreprocessTest OWNER From 984b91d31c10df2fda796277db7311169a9995b8 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:39:36 +0000 Subject: [PATCH 20/37] build: extract the complete MoE routing kernel family Convert the custom-routing object target into a focused static library exposed as tllm::kernel_moe_routing. Give it explicit ownership of all eight custom, DeepSeek, top-K-input and Llama4 routing CUDA sources, removing the latter three from the broader block-scale MoE object target. Preserve CUDA architectures, device-symbol resolution, PIC, split-compile 1 for the five custom TUs and split-compile 0 for the other three. Declare CUTLASS header/common CUDA requirements and make the existing MoE runner backend depend on routing. Preserve all production routing exports with the shared-library component list. Migrate the four-source routingKernelsTest to routing, runtime buffers and its existing Python dependency; register kernel ownership, GPU labels and a GPU resource lock. Validation: build and link the routing leaf with CUDA 13.4/SM80, verify its graph excludes the product library, residual objects, GEMM backends and Torch, check original production/generated source ownership and discovered GPU scheduling properties. GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/kernelComponents.cmake | 3 ++ .../kernels/moe/trtllmGen/CMakeLists.txt | 31 ++++++++++++++----- cpp/tests/unit_tests/kernels/CMakeLists.txt | 21 ++++++++++--- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index d30107581c47..c8213c6ee8b6 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -181,3 +181,6 @@ add_tllm_kernel_library( LINK_LIBRARIES tllm::kernel_cutlass_headers tllm::common_environment) + +list(APPEND TLLM_KERNEL_COMPONENT_TARGETS + trtllm_gen_fp8_block_scale_moe_routing) diff --git a/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt b/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt index 88bd120d0724..657d9ca1429f 100644 --- a/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt @@ -24,21 +24,36 @@ set(ROUTING_CUSTOM_SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingCustomEntry.cu ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingCustomSmallToken.cu) -list(REMOVE_ITEM SRC_CU ${ROUTING_CUSTOM_SRC_CU}) +set(ROUTING_OTHER_SRC_CU + ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingDeepSeek.cu + ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingFromTopKIds.cu + ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingLlama4.cu) +set(ROUTING_SRC_CU ${ROUTING_CUSTOM_SRC_CU} ${ROUTING_OTHER_SRC_CU}) +list(REMOVE_ITEM SRC_CU ${ROUTING_SRC_CU}) -# Build routing as multiple translation units without NVCC's internal parallel -# split pipeline: one TU per heavy kernel family (block group, small cluster, -# large cluster, small-token, entry) so ptxas runs them in parallel. -add_library(trtllm_gen_fp8_block_scale_moe_routing OBJECT - ${ROUTING_CUSTOM_SRC_CU}) +# Custom routing uses one translation unit per kernel family and disables NVCC's +# internal split pipeline so ptxas can process the families in parallel. +add_library(trtllm_gen_fp8_block_scale_moe_routing STATIC ${ROUTING_SRC_CU}) +add_library(tllm::kernel_moe_routing ALIAS + trtllm_gen_fp8_block_scale_moe_routing) +target_link_libraries(trtllm_gen_fp8_block_scale_moe_routing + PUBLIC tllm::kernel_cutlass_headers) +target_compile_features(trtllm_gen_fp8_block_scale_moe_routing + PUBLIC cxx_std_20) set_property(TARGET trtllm_gen_fp8_block_scale_moe_routing PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET trtllm_gen_fp8_block_scale_moe_routing PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) -target_compile_options(trtllm_gen_fp8_block_scale_moe_routing - PRIVATE $<$:--split-compile=1>) +set_source_files_properties( + ${ROUTING_CUSTOM_SRC_CU} + PROPERTIES COMPILE_OPTIONS "$<$:--split-compile=1>") +set_source_files_properties( + ${ROUTING_OTHER_SRC_CU} + PROPERTIES COMPILE_OPTIONS "$<$:--split-compile=0>") add_library(trtllm_gen_fp8_block_scale_moe OBJECT ${SRC_CPP} ${SRC_CU}) +target_link_libraries(trtllm_gen_fp8_block_scale_moe + PUBLIC tllm::kernel_moe_routing) set_property(TARGET trtllm_gen_fp8_block_scale_moe PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET trtllm_gen_fp8_block_scale_moe diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index dd006bba2708..58c4bad93ebc 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -208,11 +208,22 @@ foreach(target_name gemmSwigluRunnerTest;gemmSwigluKernelTestSm90Fp8) endif() endforeach() -set(ROUTING_KERNEL_TEST_SRC - moe/routing/routingTest.cpp moe/routing/routingLlama4Test.cpp - moe/routing/routingCustomTest.cpp moe/routing/routingDeepSeekTest.cpp) -add_gtest(routingKernelsTest "${ROUTING_KERNEL_TEST_SRC}") -target_link_libraries(routingKernelsTest PRIVATE Python3::Python) +add_tllm_gtest( + routingKernelsTest + OWNER + kernel + SOURCES + moe/routing/routingTest.cpp + moe/routing/routingLlama4Test.cpp + moe/routing/routingCustomTest.cpp + moe/routing/routingDeepSeekTest.cpp + LINK_LIBRARIES + tllm::kernel_moe_routing + tllm::runtime_buffers + Python3::Python + LABELS + "unit;kernels;moe-routing;gpu" + REQUIRES_GPU) add_gtest(blockScaleMoeActivationTest moe/blockScaleMoeActivationTest.cu) add_gtest(blockScaleMoeFinalizeTest moe/blockScaleMoeFinalizeTest.cu) From aad6db4303a7c69cba68458697dbb97cbc84643d Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:44:54 +0000 Subject: [PATCH 21/37] build: extract block-scale MoE activation and finalization kernels Move moe/trtllmGen/DevKernel.cu into the explicit static library tllm::kernel_moe_block_scale. Preserve its original CUDA architectures and split-compile 0 policy, declare CUTLASS header/common CUDA requirements and retain production exports. Make the existing MoE runner depend on the new component and name runner.cu explicitly, eliminating this backend's remaining recursive source globs and duplicate ownership opportunities. Migrate blockScaleMoeActivationTest and blockScaleMoeFinalizeTest to the block-scale helper library and runtime buffers. These kernel tests no longer compile the GEMM runner or generated GEMM backends. Register both with kernel-tests, block-scale/GPU labels and GPU resource locks. Validation: build/link both leaves with CUDA 13.4/SM80, verify their component-only graphs, preserved production/generated source counts and discovered GPU scheduling properties. Run the three existing host-only backing/capacity arithmetic cases; GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/kernelComponents.cmake | 9 +++++++ .../kernels/moe/trtllmGen/CMakeLists.txt | 10 +++---- cpp/tests/unit_tests/kernels/CMakeLists.txt | 26 +++++++++++++++++-- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index c8213c6ee8b6..b7331b685d20 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -184,3 +184,12 @@ add_tllm_kernel_library( list(APPEND TLLM_KERNEL_COMPONENT_TARGETS trtllm_gen_fp8_block_scale_moe_routing) + +add_tllm_kernel_library( + tllm_kernel_moe_block_scale SOURCES moe/trtllmGen/DevKernel.cu LINK_LIBRARIES + tllm::kernel_cutlass_headers) + +set_property(TARGET tllm_kernel_moe_block_scale + PROPERTY CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") +target_compile_options(tllm_kernel_moe_block_scale + PRIVATE $<$:--split-compile=0>) diff --git a/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt b/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt index 657d9ca1429f..3fc045b2d6ec 100644 --- a/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/moe/trtllmGen/CMakeLists.txt @@ -15,8 +15,6 @@ # the License. # -file(GLOB_RECURSE SRC_CPP *.cpp) -file(GLOB_RECURSE SRC_CU *.cu) set(ROUTING_CUSTOM_SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingCustomBlock.cu ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingCustomCluster.cu @@ -29,7 +27,6 @@ set(ROUTING_OTHER_SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingFromTopKIds.cu ${CMAKE_CURRENT_SOURCE_DIR}/routing/RoutingLlama4.cu) set(ROUTING_SRC_CU ${ROUTING_CUSTOM_SRC_CU} ${ROUTING_OTHER_SRC_CU}) -list(REMOVE_ITEM SRC_CU ${ROUTING_SRC_CU}) # Custom routing uses one translation unit per kernel family and disables NVCC's # internal split pipeline so ptxas can process the families in parallel. @@ -51,9 +48,10 @@ set_source_files_properties( ${ROUTING_OTHER_SRC_CU} PROPERTIES COMPILE_OPTIONS "$<$:--split-compile=0>") -add_library(trtllm_gen_fp8_block_scale_moe OBJECT ${SRC_CPP} ${SRC_CU}) -target_link_libraries(trtllm_gen_fp8_block_scale_moe - PUBLIC tllm::kernel_moe_routing) +add_library(trtllm_gen_fp8_block_scale_moe OBJECT runner.cu) +target_link_libraries( + trtllm_gen_fp8_block_scale_moe PUBLIC tllm::kernel_moe_routing + tllm::kernel_moe_block_scale) set_property(TARGET trtllm_gen_fp8_block_scale_moe PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET trtllm_gen_fp8_block_scale_moe diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 58c4bad93ebc..f41fd920097a 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -225,8 +225,30 @@ add_tllm_gtest( "unit;kernels;moe-routing;gpu" REQUIRES_GPU) -add_gtest(blockScaleMoeActivationTest moe/blockScaleMoeActivationTest.cu) -add_gtest(blockScaleMoeFinalizeTest moe/blockScaleMoeFinalizeTest.cu) +add_tllm_gtest( + blockScaleMoeActivationTest + OWNER + kernel + SOURCES + moe/blockScaleMoeActivationTest.cu + LINK_LIBRARIES + tllm::kernel_moe_block_scale + tllm::runtime_buffers + LABELS + "unit;kernels;moe-block-scale;gpu" + REQUIRES_GPU) +add_tllm_gtest( + blockScaleMoeFinalizeTest + OWNER + kernel + SOURCES + moe/blockScaleMoeFinalizeTest.cu + LINK_LIBRARIES + tllm::kernel_moe_block_scale + tllm::runtime_buffers + LABELS + "unit;kernels;moe-block-scale;gpu" + REQUIRES_GPU) add_tllm_gtest( moeLoadBalanceKernelTest From cab9008ff1ee8382b73d8fdff1f52208f2be613c Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 09:57:10 +0000 Subject: [PATCH 22/37] build: extract cascade attention and its MMHA reference Move cascadeAttentionKernel.cu from the MMHA head library to the explicit static component tllm::kernel_cascade_attention, preserving its CUDA architecture policy. Extract the top-level MMHA dispatcher as tllm::kernel_attention_decode and give the existing Linux MMHA head libraries explicit cascade/environment dependencies. On Windows, retain MMHA instantiations in their own static target rather than mixing them with decoder XQA objects. Preserve product exports and source ownership. Migrate cascadeAttentionNumericsTest to cascade and the MMHA dispatcher. It builds the actual MMHA numerical reference without XQA, generated FMHA or the monolithic library. Link the eligibility suite only to cascade; its predicate queries GPU capability when enabled, so both suites receive GPU labels/locking and join kernel-tests explicitly. Validation: compile/link both leaves with CUDA 13.4/SM80, inspect their graphs and original source counts, verify discovered scheduling metadata and execute eligibility in one process with cascade initially disabled. Numerical and enabled-eligibility GPU execution are unavailable here; the Windows branch requires a Windows toolchain. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../CMakeLists.txt | 20 +++++++++------ .../kernels/kernelComponents.cmake | 17 +++++++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 25 +++++++++++++++++-- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttention/CMakeLists.txt b/cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttention/CMakeLists.txt index 51776bc00a50..54fb3fcb1e03 100644 --- a/cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttention/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/decoderMaskedMultiheadAttention/CMakeLists.txt @@ -1,5 +1,5 @@ # -# SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & +# SPDX-FileCopyrightText: Copyright (c) 1993-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 @@ -40,11 +40,6 @@ foreach(HEAD ${basic_heads}) list(APPEND SRC_CU ${HEAD_SRCS}) endforeach() -# Cascade attention kernel. Compiled together with the basic heads so it lives -# in the same shared library as the MMHA dispatcher that calls into it. Uses Dh -# in {64, 128}. -list(APPEND SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/cascadeAttentionKernel.cu) - # skip mmha 48, 80, 96, 104, 112, 144, 160, 192 and 224 for fast build if(FAST_BUILD) set(extra_heads 256) @@ -82,9 +77,18 @@ if(NOT WIN32) PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET ${DECODER_SHARED_TARGET_1} PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) + foreach(target ${DECODER_SHARED_TARGET_0} ${DECODER_SHARED_TARGET_1}) + target_link_libraries(${target} PUBLIC tllm::common_environment + tllm::kernel_cascade_attention) + endforeach() else() - target_sources(decoder_attention_src PRIVATE ${SRC_CPP} ${SRC_CU} - ${SRC_CU_EXTRA}) + target_sources(decoder_attention_src PRIVATE ${SRC_CPP}) + add_library(tllm_mmha STATIC ${SRC_CU} ${SRC_CU_EXTRA}) + target_link_libraries(tllm_mmha PUBLIC tllm::common_environment + tllm::kernel_cascade_attention) + set_target_properties(tllm_mmha PROPERTIES POSITION_INDEPENDENT_CODE ON + CUDA_RESOLVE_DEVICE_SYMBOLS ON) + target_link_libraries(decoder_attention_src PUBLIC tllm_mmha) endif() target_link_libraries(decoder_attention_src PUBLIC nvrtc_wrapper_src diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index b7331b685d20..7f1a33896885 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -193,3 +193,20 @@ set_property(TARGET tllm_kernel_moe_block_scale PROPERTY CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") target_compile_options(tllm_kernel_moe_block_scale PRIVATE $<$:--split-compile=0>) + +add_tllm_kernel_library( + tllm_kernel_cascade_attention SOURCES + decoderMaskedMultiheadAttention/cascadeAttentionKernel.cu LINK_LIBRARIES + tllm::common_environment) +set_property(TARGET tllm_kernel_cascade_attention + PROPERTY CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}") + +if(WIN32) + set(mmha_targets tllm_mmha) + list(APPEND TLLM_KERNEL_COMPONENT_TARGETS tllm_mmha) +else() + set(mmha_targets ${DECODER_SHARED_TARGET_0} ${DECODER_SHARED_TARGET_1}) +endif() +add_tllm_kernel_library( + tllm_kernel_attention_decode SOURCES decoderMaskedMultiheadAttention.cu + LINK_LIBRARIES ${mmha_targets}) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index f41fd920097a..a0d90f1027da 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -25,8 +25,29 @@ add_tllm_gtest( LABELS "unit;kernels;logits;gpu" REQUIRES_GPU) -add_gtest(cascadeAttentionKernelTest cascadeAttentionKernelTest.cpp) -add_gtest(cascadeAttentionNumericsTest cascadeAttentionNumericsTest.cu) +add_tllm_gtest( + cascadeAttentionKernelTest + OWNER + kernel + SOURCES + cascadeAttentionKernelTest.cpp + LINK_LIBRARIES + tllm::kernel_cascade_attention + LABELS + "unit;kernels;cascade-attention;gpu" + REQUIRES_GPU) +add_tllm_gtest( + cascadeAttentionNumericsTest + OWNER + kernel + SOURCES + cascadeAttentionNumericsTest.cu + LINK_LIBRARIES + tllm::kernel_cascade_attention + tllm::kernel_attention_decode + LABELS + "unit;kernels;cascade-attention;gpu" + REQUIRES_GPU) macro(remove_compile_definition TARGET_NAME DEFINITION) get_target_property(DEFS ${TARGET_NAME} COMPILE_DEFINITIONS) From c309a36d3f5fcae45984a5ce314e148ed26e7d36 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:00:52 +0000 Subject: [PATCH 23/37] build: expose generated FMHA as a focused static component Convert trtllm_gen_fmha from an object library to the static component tllm::kernel_attention. Name fmhaRunner.cpp and fmhaReduction.cu explicitly, retain generated cubin archive sources and prebuilt FMHA/core libraries, and declare mask preparation, environment, CUTLASS header and CUDA driver dependencies. Preserve architecture pruning, Rubin metadata, compile definitions and device-symbol resolution. Whole-archive the component only in the product library to retain all exports and cubin registration. Migrate fmhaDsv4EpilogueFusionTest to this attention family and runtime buffers, with kernel aggregate ownership, FMHA/GPU labels and locking. The numerical fusion leaf builds its actual generated attention backend without decoder XQA, unrelated GEMM implementations, Torch or the monolith. Validation: build and link with CUDA 13.4/SM80, verify the focused Ninja graph, original production/generated source ownership and discovered GPU properties. Numerical execution on supported GPU hardware is unavailable here; generated/prebuilt backend architecture support remains unchanged. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 2 ++ .../kernels/trtllmGenKernels/fmha/CMakeLists.txt | 16 ++++++++++------ cpp/tests/unit_tests/kernels/CMakeLists.txt | 13 ++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 7f1a33896885..299b62e05f22 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -210,3 +210,5 @@ endif() add_tllm_kernel_library( tllm_kernel_attention_decode SOURCES decoderMaskedMultiheadAttention.cu LINK_LIBRARIES ${mmha_targets}) + +list(APPEND TLLM_KERNEL_COMPONENT_TARGETS trtllm_gen_fmha) diff --git a/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt b/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt index c251d3b9f613..6a0ada3ccb00 100644 --- a/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/CMakeLists.txt @@ -46,9 +46,8 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/trtllmGen_fmha_export/KernelParamsDecl.h ${CMAKE_CURRENT_BINARY_DIR}/KernelParamsDecl.h COPYONLY) -file(GLOB_RECURSE SRC_CPP *.cpp) -file(GLOB_RECURSE SRC_CU *.cu) -list(REMOVE_ITEM SRC_CU "${CMAKE_CURRENT_SOURCE_DIR}/prepareCustomMask.cu") +set(SRC_CPP ${CMAKE_CURRENT_SOURCE_DIR}/fmhaRunner.cpp) +set(SRC_CU ${CMAKE_CURRENT_SOURCE_DIR}/fmhaReduction.cu) # Archs listed here are pruned when the build does not enable them. Sm100f has # no context FMHA kernel, so Rubin needs the prebuilt Sm107a cubins kept @@ -65,11 +64,16 @@ target_include_directories( trtllm_gen_fmha_interface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/trtllmGen_fmha_export) -add_library(trtllm_gen_fmha OBJECT ${SRC_CPP} ${SRC_CU}) +add_library(trtllm_gen_fmha STATIC ${SRC_CPP} ${SRC_CU}) +add_library(tllm::kernel_attention ALIAS trtllm_gen_fmha) +target_compile_features(trtllm_gen_fmha PUBLIC cxx_std_20) set_property(TARGET trtllm_gen_fmha PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET trtllm_gen_fmha PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) -target_link_libraries(trtllm_gen_fmha PUBLIC trtllm_gen_fmha_interface - tllm::kernel_attention_mask) +target_link_libraries( + trtllm_gen_fmha + PUBLIC trtllm_gen_fmha_interface tllm::kernel_attention_mask + tllm::common_environment tllm::kernel_cutlass_headers + CUDA::cuda_driver) target_include_directories( trtllm_gen_fmha PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/trtllmGen_fmha_export) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index a0d90f1027da..073e9cab2e72 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -344,7 +344,18 @@ add_tllm_gtest( LABELS "unit;kernels;attention-mask;gpu" REQUIRES_GPU) -add_gtest(fmhaDsv4EpilogueFusionTest fmhaDsv4EpilogueFusionTest.cpp) +add_tllm_gtest( + fmhaDsv4EpilogueFusionTest + OWNER + kernel + SOURCES + fmhaDsv4EpilogueFusionTest.cpp + LINK_LIBRARIES + tllm::kernel_attention + tllm::runtime_buffers + LABELS + "unit;kernels;fmha;gpu" + REQUIRES_GPU) add_tllm_gtest( nvfp4ColdPageKernelsTest From a50d82dad8af08ee7b9e5976959b3d53b89901ed Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:04:56 +0000 Subject: [PATCH 24/37] build: extract cuBLAS matrix-wrapper support for kernel leaves Move cublasMMWrapper.cpp from common_src into the focused static library tllm::common_cublas. Declare common CUDA, cuBLAS and cuBLASLt dependencies, C++20/PIC requirements and the existing optional FP4 compile definition. Make residual common callers link this owner instead of recompiling it, and retain all shared-library exports with a whole-archive override. The CUTLASS MoE runner references LoRA's cuBLAS path even when a test does not enable LoRA. Giving the matrix wrapper a separate owner lets that real dependency be satisfied without pulling attention, distributed GPU utilities and the rest of common_src into a kernel-family leaf. Validation: build the wrapper with the CUDA 13.4/SM80 toolchain, inspect its graph to exclude residual object targets, unrelated kernel backends, Torch and the monolith, and preserve original common/kernel production source compilation counts. Runtime cuBLAS execution requires a GPU. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 5 ++++- cpp/tensorrt_llm/common/CMakeLists.txt | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index aa37050fb825..bb50726e87ed 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -274,7 +274,7 @@ target_link_libraries( ${SHARED_TARGET} PRIVATE $ - $ + $ $ $ $ @@ -287,6 +287,9 @@ foreach(component IN LISTS TLLM_KERNEL_COMPONENT_TARGETS) PROPERTY LINK_LIBRARY_OVERRIDE_${component} WHOLE_ARCHIVE) endforeach() +set_property(TARGET ${SHARED_TARGET} + PROPERTY LINK_LIBRARY_OVERRIDE_tllm_common_cublas WHOLE_ARCHIVE) + # Components also link each other normally; retain all component exports here. set_property(TARGET ${SHARED_TARGET} PROPERTY LINK_LIBRARY_OVERRIDE_tllm_common_error WHOLE_ARCHIVE) diff --git a/cpp/tensorrt_llm/common/CMakeLists.txt b/cpp/tensorrt_llm/common/CMakeLists.txt index 6b63f13eaf3a..8a266e2bdbea 100644 --- a/cpp/tensorrt_llm/common/CMakeLists.txt +++ b/cpp/tensorrt_llm/common/CMakeLists.txt @@ -74,10 +74,21 @@ target_link_libraries(tllm_common_environment PUBLIC tllm::common_cuda) set_target_properties(tllm_common_environment PROPERTIES POSITION_INDEPENDENT_CODE ON) +add_library(tllm_common_cublas STATIC cublasMMWrapper.cpp) +add_library(tllm::common_cublas ALIAS tllm_common_cublas) +target_link_libraries(tllm_common_cublas PUBLIC tllm::common_cuda CUDA::cublas + CUDA::cublasLt) +target_compile_features(tllm_common_cublas PUBLIC cxx_std_20) +set_target_properties(tllm_common_cublas PROPERTIES POSITION_INDEPENDENT_CODE + ON) +if(ENABLE_CUBLASLT_FP4_GEMM) + target_compile_definitions(tllm_common_cublas + PRIVATE ENABLE_CUBLASLT_FP4_GEMM) +endif() + add_library( common_src OBJECT attentionOp.cpp - cublasMMWrapper.cpp cudaFp8Utils.cu cudaProfilerUtils.cpp mcastDevMemUtils.cpp @@ -88,7 +99,8 @@ add_library( add_cuda_architectures(common_src 89) set_property(TARGET common_src PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET common_src PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON) -target_link_libraries(common_src PUBLIC trtllm_gen_fmha_interface) +target_link_libraries(common_src PUBLIC trtllm_gen_fmha_interface + tllm::common_cublas) if(ENABLE_CUBLASLT_FP4_GEMM) target_compile_definitions(common_src PRIVATE ENABLE_CUBLASLT_FP4_GEMM) From b82f50c68a781feafe5cb2d512c1178ab95b6077 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:08:18 +0000 Subject: [PATCH 25/37] build: extract LoRA adapter and grouped-GEMM kernel support Create tllm::kernel_lora with explicit ownership of the LoRA/DoRA adapters, grouped and split-K grouped GEMM, fused parameter-fill/row-reorder and DoRA scaling sources. Remove all six files from kernels_src and declare focused cuBLAS wrapper, CUTLASS header, runtime-buffer and environment dependencies. Preserve root-kernel architectures, type instantiations and all shared-library exports. CUTLASS MoE's runner references these real LoRA paths even when a unit case disables LoRA. This focused component supplies those symbols without linking residual kernel/common object libraries or a product-level stub. Keep the existing adapter implementation and backend dispatch unchanged. Validation: compile/archive the family with CUDA 13.4/SM80, inspect its graph for monolithic, Torch and residual object dependencies, and preserve original common/kernel source compilation counts. The subsequent MoE leaf link checks the actual host-symbol closure; GPU execution is unavailable. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 299b62e05f22..5f74c862f911 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -212,3 +212,18 @@ add_tllm_kernel_library( LINK_LIBRARIES ${mmha_targets}) list(APPEND TLLM_KERNEL_COMPONENT_TARGETS trtllm_gen_fmha) + +add_tllm_kernel_library( + tllm_kernel_lora + SOURCES + groupGemm.cu + splitkGroupGemm.cu + lora/lora.cpp + lora/dora.cpp + lora/loraGroupGEMMParamFillRowReorderFusion.cu + doraScaling.cu + LINK_LIBRARIES + tllm::common_cublas + tllm::kernel_cutlass_headers + tllm::runtime_buffers + tllm::common_environment) From c5972208c3f5324e65ae8298768f6c9455648c75 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:11:46 +0000 Subject: [PATCH 26/37] build: extract shared CUDA quantization kernels Assign quantization.cu to the explicit static component tllm::kernel_quantization and remove it from kernels_src. Declare common CUDA and environment dependencies, preserve the original architecture policy and quantization instantiations, and retain all product exports through the shared-library component list. The CUTLASS MoE test directly exercises FP4 weight quantization when preparing its inputs. Giving quantization its own owner lets the MoE leaf declare that dependency without compiling residual attention, communication and unrelated kernel sources. Keep numerical kernels and FP16/BF16/FP8/FP4 feature gating unchanged. Validation: compile/archive the family with CUDA 13.4/SM80, verify its Ninja graph excludes residual object targets, Torch and the monolith, and preserve original common/kernel source compilation counts. The subsequent MoE leaf link checks quantization symbols; GPU execution is unavailable. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 5f74c862f911..ac60b966cfc2 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -227,3 +227,6 @@ add_tllm_kernel_library( tllm::kernel_cutlass_headers tllm::runtime_buffers tllm::common_environment) + +add_tllm_kernel_library(tllm_kernel_quantization SOURCES quantization.cu + LINK_LIBRARIES tllm::common_environment) From 65e0fb53acc712494b444935db11dd77593af6a8 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:15:11 +0000 Subject: [PATCH 27/37] build: separate shared pre-quantization scaling kernels Give preQuantScaleKernel.cu its own explicitly sourced static library, tllm::kernel_pre_quant_scale, and make weight-only GEMV depend on it. Preserve CUDA architectures and production exports while keeping exactly one compilation owner for the shared scaling implementations. CUTLASS MoE also calls the per-channel and per-expert scaling entrypoints. A separate component lets it link that actual dependency without building the 24 weight-only GEMV dispatch translation units. Existing weight-only callers keep the scaling symbols through their declared dependency. Validation: rebuild/link weightOnlyKernelTest with CUDA 13.4/SM80, verify its focused graph and unchanged source compilation counts, and inspect discovered GPU labels/resource locks. GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index ac60b966cfc2..2868cc271ea7 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -153,7 +153,6 @@ set_property(TARGET tllm_kernel_int8_gemm add_tllm_kernel_library( tllm_kernel_weight_only SOURCES - preQuantScaleKernel.cu weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorFalse.cu weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorInterleavedForHopperTrue.cu weightOnlyBatchedGemv/kernelDispatcherBf16Int4GroupwiseColumnMajorInterleavedTrue.cu @@ -230,3 +229,8 @@ add_tllm_kernel_library( add_tllm_kernel_library(tllm_kernel_quantization SOURCES quantization.cu LINK_LIBRARIES tllm::common_environment) + +add_tllm_kernel_library(tllm_kernel_pre_quant_scale SOURCES + preQuantScaleKernel.cu) +target_link_libraries(tllm_kernel_weight_only + PUBLIC tllm::kernel_pre_quant_scale) From 39078c334b99a17b5d69ef5a45ae0d41f8ef1029 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:29:40 +0000 Subject: [PATCH 28/37] build: expose the FP8 block-scale GEMM component List the GEMM runner and packed quantization CUDA sources explicitly and expose the existing static backend as tllm::kernel_fp8_block_scale_gemm. Declare common environment, GEMM utility, CUDA driver and configured NVRTC dependencies so clients can link the real runner without the monolithic library. Preserve the existing CUTLASS architecture and compile policies and product linkage. The CUTLASS MoE launcher instantiates this runner even when a test uses other weight formats; this component supplies that production dependency. Validation: build the static component with CUDA 13.4/SM80 and verify original source ownership counts. GPU execution is unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index 1fc95c08adfc..fa1de16ad2d4 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -172,7 +172,10 @@ file(GLOB_RECURSE GROUPED_SRC_CU ${MOE_CUTLASS_DIR}/*.cu) file(GLOB_RECURSE FBGEMM_SRC_CU fp8_rowwise_gemm/*.cu) # Get the sources for FP8 Blockwise GEMM launchers -file(GLOB_RECURSE FP8_BLOCKSCALE_GEMM_SRC_CU fp8_blockscale_gemm/*.cu) +set(FP8_BLOCKSCALE_GEMM_SRC_CU + ${CMAKE_CURRENT_SOURCE_DIR}/fp8_blockscale_gemm/fp8_blockscale_gemm.cu + ${CMAKE_CURRENT_SOURCE_DIR}/fp8_blockscale_gemm/fp8_blockscale_quant_packed.cu +) # Get the sources for FP4 GEMM launchers file(GLOB_RECURSE FP4_SRC_CU fp4_gemm/*.cu) @@ -238,6 +241,11 @@ set_cuda_architectures(fb_gemm_src ${CUTLASS_COMMON_ARCHS}) # ${INSTANTIATION_GENERATION_DIR}/fp8_rowwise_gemm) add_library(fp8_blockscale_gemm_src STATIC ${FP8_BLOCKSCALE_GEMM_SRC_CU}) +add_library(tllm::kernel_fp8_block_scale_gemm ALIAS fp8_blockscale_gemm_src) +target_link_libraries( + fp8_blockscale_gemm_src + PUBLIC tllm::kernel_gemm_utilities tllm::common_environment CUDA::cuda_driver + ${NVRTC_LIB} ${NVRTC_BUILTINS_LIB}) set_cuda_architectures(fp8_blockscale_gemm_src ${CUTLASS_COMMON_ARCHS}) set(GEMM_SWIGLU_SM90_SRC_CU From 527d7e96aa9f239fa4992182416a361cbe5b90c1 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:34:12 +0000 Subject: [PATCH 29/37] build: migrate CUTLASS MoE tests to explicit kernel components Expose the existing CUTLASS MoE static backend as tllm::kernel_moe and name its CUDA implementation files explicitly. Preserve datatype/feature selection, generated GEMM instantiations, per-architecture object targets and compile policies. Declare GEMM utilities, FP8 block-scale GEMM, LoRA, pre-quantization scaling and environment dependencies. Retain product exports through the shared-library component list. Migrate mixtureOfExpertsTest to the actual MoE backend, CUDA quantization and runtime buffers, with kernel ownership, GPU labels and resource locking. Provide an interface for the real internal CUTLASS archive and use it for the optional internal test and non-OSS configuration. Preserve the internal-source availability check and OSS macro removal. No stub implementations or residual kernel/common objects satisfy backend symbols. Validation: kernel-tests builds with CUDA 13.4/SM80. All 26 configured kernel leaf graphs exclude Torch, the monolith and residual object libraries. Original common/kernel/backend source counts are preserved; discovered GPU tests retain scheduling locks. Four representative leaves also build in a fresh full-project tree without producing the monolith. GPU execution and the optional internal-source variant require environments unavailable here. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- .../kernels/cutlass_kernels/CMakeLists.txt | 27 +++++++++++++++- .../kernels/kernelComponents.cmake | 13 ++++++++ cpp/tests/unit_tests/kernels/CMakeLists.txt | 31 +++++++++++++++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt index fa1de16ad2d4..e9a552545e69 100644 --- a/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt +++ b/cpp/tensorrt_llm/kernels/cutlass_kernels/CMakeLists.txt @@ -272,7 +272,26 @@ if(USING_OSS_CUTLASS_FP4_GEMM) endif() if(USING_OSS_CUTLASS_MOE_GEMM) - file(GLOB MOE_GEMM_SRC_CU "${MOE_CUTLASS_DIR}/*.cu") + set(MOE_GEMM_SRC_CU + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_bf16_bf16.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_bf16_fp4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_bf16_fp8.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_bf16_uint4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_bf16_uint8.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp16_fp16.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp16_fp4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp16_uint4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp16_uint8.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp32_fp32.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp4_fp4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp8_fp4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp8_fp8.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_kernels_fp8_uint4.cu" + "${MOE_CUTLASS_DIR}/moe_gemm_tma_warp_specialized_input.cu" + "${MOE_CUTLASS_DIR}/moe_kernels.cu" + "${MOE_CUTLASS_DIR}/moe_lora_pointer_expand.cu" + "${MOE_CUTLASS_DIR}/moe_lora_problem_builder.cu" + "${MOE_CUTLASS_DIR}/moe_lora_slot_expand.cu") list( REMOVE_ITEM MOE_GEMM_SRC_CU "${MOE_CUTLASS_DIR}/moe_lora_pointer_expand.cu" "${MOE_CUTLASS_DIR}/moe_lora_problem_builder.cu" @@ -293,6 +312,12 @@ if(USING_OSS_CUTLASS_MOE_GEMM) list(FILTER MOE_GEMM_SRC_CU EXCLUDE REGEX ".*fp8.*") add_library(moe_gemm_src STATIC ${MOE_GEMM_SRC_CU} ${GROUPED_SRC_CPP}) + add_library(tllm::kernel_moe ALIAS moe_gemm_src) + target_link_libraries( + moe_gemm_src + PUBLIC tllm::kernel_gemm_utilities tllm::kernel_fp8_block_scale_gemm + tllm::kernel_lora tllm::kernel_pre_quant_scale + tllm::common_environment) add_library(_moe_gemm_launcher OBJECT ${MOE_GEMM_SRC_CU_LAUNCHER}) add_cuda_architectures(_moe_gemm_launcher 89) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 2868cc271ea7..90156ea741a4 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -234,3 +234,16 @@ add_tllm_kernel_library(tllm_kernel_pre_quant_scale SOURCES preQuantScaleKernel.cu) target_link_libraries(tllm_kernel_weight_only PUBLIC tllm::kernel_pre_quant_scale) + +add_library(tllm_kernel_moe_internal INTERFACE) +add_library(tllm::kernel_moe_internal ALIAS tllm_kernel_moe_internal) +target_link_libraries( + tllm_kernel_moe_internal + INTERFACE ${INTERNAL_CUTLASS_KERNELS_TARGET} CUDA::cuda_driver + tllm::kernel_gemm_utilities tllm::kernel_lora + tllm::kernel_pre_quant_scale tllm::common_environment) +if(USING_OSS_CUTLASS_MOE_GEMM) + list(APPEND TLLM_KERNEL_COMPONENT_TARGETS moe_gemm_src) +else() + add_library(tllm::kernel_moe ALIAS tllm_kernel_moe_internal) +endif() diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index 073e9cab2e72..aae61981941f 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -58,15 +58,40 @@ macro(remove_compile_definition TARGET_NAME DEFINITION) endif() endmacro() -add_gtest(mixtureOfExpertsTest moe/mixtureOfExpertsTest.cu) +add_tllm_gtest( + mixtureOfExpertsTest + OWNER + kernel + SOURCES + moe/mixtureOfExpertsTest.cu + LINK_LIBRARIES + tllm::kernel_moe + tllm::kernel_quantization + tllm::runtime_buffers + LABELS + "unit;kernels;moe;gpu" + REQUIRES_GPU) # If we are using oss cutlass, build an explicit internal test if(USING_OSS_CUTLASS_MOE_GEMM) target_compile_definitions(mixtureOfExpertsTest PUBLIC USING_OSS_CUTLASS_MOE_GEMM) - add_gtest(mixtureOfExpertsInternalTest moe/mixtureOfExpertsTest.cu - TEST_PREFIX "Internal.") + add_tllm_gtest( + mixtureOfExpertsInternalTest + TEST_PREFIX + "Internal." + OWNER + kernel + SOURCES + moe/mixtureOfExpertsTest.cu + LINK_LIBRARIES + tllm::kernel_moe_internal + tllm::kernel_quantization + tllm::runtime_buffers + LABELS + "unit;kernels;moe;gpu" + REQUIRES_GPU) remove_compile_definition(mixtureOfExpertsInternalTest USING_OSS_CUTLASS_MOE_GEMM) endif() From 70ea18535a13f266a2405417c0bc26d78b485381 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 19:25:12 +0000 Subject: [PATCH 30/37] [None][fix] link internal MoE component to FP8 block-scale GEMM The bundled CUTLASS MoE archive references CutlassFp8BlockScaleGemmRunner, but the internal MoE component did not propagate its provider library. Component-local tests therefore failed to link after losing the shared library link graph. Declare the FP8 block-scale GEMM dependency on tllm_kernel_moe_internal so both explicit internal tests and non-OSS MoE consumers inherit it. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/kernels/kernelComponents.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpp/tensorrt_llm/kernels/kernelComponents.cmake b/cpp/tensorrt_llm/kernels/kernelComponents.cmake index 90156ea741a4..206346bfbf78 100644 --- a/cpp/tensorrt_llm/kernels/kernelComponents.cmake +++ b/cpp/tensorrt_llm/kernels/kernelComponents.cmake @@ -239,9 +239,13 @@ add_library(tllm_kernel_moe_internal INTERFACE) add_library(tllm::kernel_moe_internal ALIAS tllm_kernel_moe_internal) target_link_libraries( tllm_kernel_moe_internal - INTERFACE ${INTERNAL_CUTLASS_KERNELS_TARGET} CUDA::cuda_driver - tllm::kernel_gemm_utilities tllm::kernel_lora - tllm::kernel_pre_quant_scale tllm::common_environment) + INTERFACE ${INTERNAL_CUTLASS_KERNELS_TARGET} + CUDA::cuda_driver + tllm::kernel_gemm_utilities + tllm::kernel_fp8_block_scale_gemm + tllm::kernel_lora + tllm::kernel_pre_quant_scale + tllm::common_environment) if(USING_OSS_CUTLASS_MOE_GEMM) list(APPEND TLLM_KERNEL_COMPONENT_TARGETS moe_gemm_src) else() From 92d2423ffe60e6db51794bcbede489f2dfd8de7d Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Fri, 23 Oct 2026 09:52:19 +0000 Subject: [PATCH 31/37] build: link whole-archive components in a foreach loop List each TensorRT-LLM component separately and apply the whole-archive link expression in a foreach loop. Preserve the existing component order and private link visibility. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index bb50726e87ed..06f7702ceeee 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -270,15 +270,33 @@ endif() target_link_libraries(${SHARED_TARGET} PUBLIC ${TRTLLM_LINK_LIBS}) -target_link_libraries( - ${SHARED_TARGET} - PRIVATE - $ - $ - $ - $ - $ - $) +foreach( + component + tllm_common_error + tllm_common_logging + tllm_common_cuda + tllm_executor_types + tllm_executor_serialization + tllm_runtime_memory + tllm_runtime_buffers + tllm_runtime_distributed + tllm_runtime_topology + tllm_common_cublas + tllm_common_environment + tllm_executor_values + tllm_executor_transfer_agent + tllm_kv_cache_host_memory + tllm_kv_cache + tllm_kv_cache_legacy + tllm_batch_scheduler + tllm_kernel_kv_cache_copy + ${BATCH_MANAGER_TARGET} + ${EXECUTOR_TARGET} + fp8_blockscale_gemm_src + ${INTERNAL_CUTLASS_KERNELS_TARGET}) + target_link_libraries(${SHARED_TARGET} + PRIVATE $) +endforeach() foreach(component IN LISTS TLLM_KERNEL_COMPONENT_TARGETS) target_link_libraries(${SHARED_TARGET} From 0b16b45b212fc90c765aa2d859ca0aca710ecc00 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:52:05 -0700 Subject: [PATCH 32/37] [None][fix] keep CUDA payloads beyond host sections on AArch64 The component-library split links additional kernel archives into libtensorrt_llm.so with WHOLE_ARCHIVE. With the SBSA multi-architecture build, the embedded CUDA payloads separate host text from its unwind tables far enough to overflow signed 32-bit R_AARCH64_PREL32 relocations in .eh_frame and prevent the shared-library link from completing. Add a supplemental ELF linker script that places .nv_fatbin and __nv_relfatbin after .bss, keeping host code, unwind tables, and host data close together. Leave .nvFatBinSegment registration wrappers near host data. INSERT AFTER augments the default linker layout rather than replacing the platform's complete linker script. Apply the script privately to the tensorrt_llm shared target on Linux AArch64 and register it in LINK_DEPENDS so changes trigger relinking. Preserve the component-library structure, WHOLE_ARCHIVE exports, and exception-unwinding support without changing other platform links. Validation in the running AArch64 container using build_sbsa, originally configured by run_build_wheel_arm.sh: - Reproduced the original R_AARCH64_PREL32 relocation overflow. - Regenerated CMake and verified the Ninja link rule includes the script as both a linker option and an input dependency. - Successfully linked libtensorrt_llm.so with the generated command. - Inspected the resulting ELF section layout with readelf. - Passed library-loading, exception-unwinding through the shared library, and backtrace smoke checks. - Passed git diff --check. Full wheel packaging was not rerun. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/cmake/templates/cuda_fatbin.ld | 26 ++++++++++++++++++++++++++ cpp/tensorrt_llm/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 cpp/cmake/templates/cuda_fatbin.ld diff --git a/cpp/cmake/templates/cuda_fatbin.ld b/cpp/cmake/templates/cuda_fatbin.ld new file mode 100644 index 000000000000..d18d0aebc661 --- /dev/null +++ b/cpp/cmake/templates/cuda_fatbin.ld @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. + * + * 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. + */ + +/* Augment the default ELF layout. CUDA payloads can exceed 2 GiB, so place + * them after host code, unwind tables, and data. Keep .nvFatBinSegment (the + * registration wrappers containing pointers to the payloads) near host data. + */ +SECTIONS +{ + .nv_fatbin : { *(.nv_fatbin) } + __nv_relfatbin : { *(__nv_relfatbin) } +} +INSERT AFTER .bss; diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index 06f7702ceeee..d50044751eb1 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -259,6 +259,18 @@ set_target_properties( PROPERTIES CXX_STANDARD "20" CXX_STANDARD_REQUIRED "YES" CXX_EXTENSIONS "NO" LINK_FLAGS "${AS_NEEDED_FLAG} ${UNDEFINED_FLAG}") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL + "aarch64") + # Keep large CUDA payloads out of the signed 32-bit displacement between host + # code and its unwind tables. + set(CUDA_FATBIN_LINKER_SCRIPT + "${PROJECT_SOURCE_DIR}/cmake/templates/cuda_fatbin.ld") + target_link_options(${SHARED_TARGET} PRIVATE + "LINKER:-T,${CUDA_FATBIN_LINKER_SCRIPT}") + set_property(TARGET ${SHARED_TARGET} APPEND + PROPERTY LINK_DEPENDS "${CUDA_FATBIN_LINKER_SCRIPT}") +endif() + # Keep statically linked NVRTC symbols local so they cannot be interposed by a # dynamic NVRTC loaded elsewhere in the process. if(NOT WIN32 AND NOT NVRTC_DYNAMIC_LINKING) From dfcf501fdd6eff2a5571d09f8b5961e0d93472f0 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 10:00:44 +0000 Subject: [PATCH 33/37] [None][fix] keep CUDA payloads beyond host sections on x86-64 Extend the existing Linux CUDA fatbin linker layout from AArch64 to x86-64. Multi-architecture payloads can push the GOT and other host sections beyond the signed 32-bit PC-relative range, causing GOTPCRELX truncation and PLT offset overflow when linking libtensorrt_llm.so. Reuse cuda_fatbin.ld to place .nv_fatbin and __nv_relfatbin after .bss while retaining CUDA registration wrappers near host data. Keep the current code model and BOLT settings. Validation: a sparse 2 GiB PROGBITS CUDA-payload reproducer fails with the default layout and links successfully with this script. A minimal CMake project using the changed block verifies Linux x86-64 and AArch64 receive the script while Windows does not. Full wheel rebuild is not validated because the failed build's intermediate objects have been removed. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index d50044751eb1..6f1fcadf8097 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -259,10 +259,10 @@ set_target_properties( PROPERTIES CXX_STANDARD "20" CXX_STANDARD_REQUIRED "YES" CXX_EXTENSIONS "NO" LINK_FLAGS "${AS_NEEDED_FLAG} ${UNDEFINED_FLAG}") -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL - "aarch64") - # Keep large CUDA payloads out of the signed 32-bit displacement between host - # code and its unwind tables. +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES + "^(aarch64|x86_64)$") + # Keep host code, unwind tables, and the GOT within PC-relative addressing + # range by placing large CUDA payloads after host data. set(CUDA_FATBIN_LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/cmake/templates/cuda_fatbin.ld") target_link_options(${SHARED_TARGET} PRIVATE From 90ba442ca75f52ad2512c11372a5545ba71fc575 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 10:16:45 +0000 Subject: [PATCH 34/37] [None][fix] apply CUDA payload layout to decoder libraries Apply the existing Linux CUDA fatbin linker script to decoder_attention_0 and decoder_attention_1 alongside the main TensorRT-LLM shared library. The second decoder library contains more than 2 GiB of CUDA payloads in multi-architecture builds, which otherwise separate host code from the GOT and data and cause GOTPCRELX, PC32, and PLT relocation overflows. Reuse the existing target configuration block and track the script in LINK_DEPENDS for all three libraries so script changes trigger relinking. Validation: checked generated linker commands and script dependencies for all three targets on Linux x86-64, Linux AArch64, and Windows. Both real decoder libraries relink successfully with the script using the retained build objects, including the previously failing decoder_attention_1 target. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index 6f1fcadf8097..8ff87d6522fb 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -265,10 +265,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES # range by placing large CUDA payloads after host data. set(CUDA_FATBIN_LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/cmake/templates/cuda_fatbin.ld") - target_link_options(${SHARED_TARGET} PRIVATE - "LINKER:-T,${CUDA_FATBIN_LINKER_SCRIPT}") - set_property(TARGET ${SHARED_TARGET} APPEND - PROPERTY LINK_DEPENDS "${CUDA_FATBIN_LINKER_SCRIPT}") + foreach(target ${SHARED_TARGET} ${DECODER_SHARED_TARGET_0} + ${DECODER_SHARED_TARGET_1}) + target_link_options(${target} PRIVATE + "LINKER:-T,${CUDA_FATBIN_LINKER_SCRIPT}") + set_property(TARGET ${target} APPEND + PROPERTY LINK_DEPENDS "${CUDA_FATBIN_LINKER_SCRIPT}") + endforeach() endif() # Keep statically linked NVRTC symbols local so they cannot be interposed by a From 68cc086ea7b9bfdfe265b82729bb7080c78124b1 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 10:24:01 +0000 Subject: [PATCH 35/37] [None][build] simplify Linux CUDA payload layout guard Remove the CMAKE_SYSTEM_PROCESSOR matcher from the CUDA payload linker-script condition. Earlier architecture validation already limits supported Linux targets to x86-64 and AArch64, and both use the same layout policy. Keep the Linux guard and apply the script to the main shared library and both decoder libraries as before. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tensorrt_llm/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index 8ff87d6522fb..bae1bfd62d88 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -259,8 +259,7 @@ set_target_properties( PROPERTIES CXX_STANDARD "20" CXX_STANDARD_REQUIRED "YES" CXX_EXTENSIONS "NO" LINK_FLAGS "${AS_NEEDED_FLAG} ${UNDEFINED_FLAG}") -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES - "^(aarch64|x86_64)$") +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Keep host code, unwind tables, and the GOT within PC-relative addressing # range by placing large CUDA payloads after host data. set(CUDA_FATBIN_LINKER_SCRIPT From 04000c3ea989a1fe81d320bbfec4576f2779c145 Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:37:57 +0000 Subject: [PATCH 36/37] [None][fix] place CUDA payloads before host sections for BOLT BOLT normally appends rewritten code and unwind information after the last loadable segment. Placing large CUDA payloads after .bss therefore leaves BOLT's relocated .eh_frame too far from the original host code for signed 32-bit PC-relative references. Build-SBSA run 11350 failed while consuming the main AArch64 profile with LLVM BOLT 21.1.5. Its failing reference required a displacement of -2,181,430,481 bytes, exceeding the signed 32-bit range by 32.37 MiB. The same failure reproduces without a stale profile, so refreshing profiles alone does not address the underlying layout constraint. Move .nv_fatbin and __nv_relfatbin before .dynsym instead of after .bss. This keeps the original host code, unwind tables, GOT, and appended BOLT output together after the CUDA payloads. Keep .nvFatBinSegment registration wrappers near host data. Use .dynsym as the insertion anchor because both GNU ld and LLD place it before host code and unwind sections; their .init ordering differs. Update the CMake comment to describe this layout. Validation performed in the running AArch64 build container: - Reproduced the Delta32 overflow with LLVM BOLT 21.1.5 and the CI optimization flags using a minimal binary with a 3 GiB mapped payload. - Applied the promoted profile to an isolated relink of the existing local TensorRT-LLM library: the trailing-payload layout failed with the same .relocated.eh_frame error, while a leading-payload layout passed BOLT. - Successfully loaded the rewritten TensorRT-LLM shared library. - Tested the final linker script with GNU ld and Clang/LLD using a 3 GiB CUDA-like payload; BOLT, dlopen, normal calls, and C++ exception unwinding all passed. - git diff --check passed. The real-library comparison used the existing local GCC build. A complete Clang-built CI wheel rebuild remains to be validated. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/cmake/templates/cuda_fatbin.ld | 10 ++++++---- cpp/tensorrt_llm/CMakeLists.txt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/cmake/templates/cuda_fatbin.ld b/cpp/cmake/templates/cuda_fatbin.ld index d18d0aebc661..f3a8920fe436 100644 --- a/cpp/cmake/templates/cuda_fatbin.ld +++ b/cpp/cmake/templates/cuda_fatbin.ld @@ -14,13 +14,15 @@ * limitations under the License. */ -/* Augment the default ELF layout. CUDA payloads can exceed 2 GiB, so place - * them after host code, unwind tables, and data. Keep .nvFatBinSegment (the - * registration wrappers containing pointers to the payloads) near host data. +/* CUDA payloads can exceed 2 GiB. Place them before all host code so that + * code, unwind tables, the GOT, and code appended by BOLT remain close to + * each other. Keep .nvFatBinSegment (the registration wrappers containing + * pointers to the payloads) near host data. + * .dynsym precedes both code and unwind sections in GNU ld and LLD layouts. */ SECTIONS { .nv_fatbin : { *(.nv_fatbin) } __nv_relfatbin : { *(__nv_relfatbin) } } -INSERT AFTER .bss; +INSERT BEFORE .dynsym; diff --git a/cpp/tensorrt_llm/CMakeLists.txt b/cpp/tensorrt_llm/CMakeLists.txt index bae1bfd62d88..cc9a64e71544 100644 --- a/cpp/tensorrt_llm/CMakeLists.txt +++ b/cpp/tensorrt_llm/CMakeLists.txt @@ -261,7 +261,7 @@ set_target_properties( if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # Keep host code, unwind tables, and the GOT within PC-relative addressing - # range by placing large CUDA payloads after host data. + # range, including after BOLT appends code, by placing CUDA payloads first. set(CUDA_FATBIN_LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/cmake/templates/cuda_fatbin.ld") foreach(target ${SHARED_TARGET} ${DECODER_SHARED_TARGET_0} From 6d841335e92685639f802e64fcae78f206d569cf Mon Sep 17 00:00:00 2001 From: Robin Kobus <19427718+Funatiq@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:43:32 +0000 Subject: [PATCH 37/37] [None][test] remove GPU resource locks added by kernel test migration Remove REQUIRES_GPU from the 26 migrated kernel test registrations and the explicit GPU resource lock from gemmSwigluKernelTestSm90Fp8. These tests do not need CTest to serialize execution through a shared GPU lock. Signed-off-by: Robin Kobus <19427718+Funatiq@users.noreply.github.com> --- cpp/tests/unit_tests/kernels/CMakeLists.txt | 83 +++++++-------------- 1 file changed, 28 insertions(+), 55 deletions(-) diff --git a/cpp/tests/unit_tests/kernels/CMakeLists.txt b/cpp/tests/unit_tests/kernels/CMakeLists.txt index aae61981941f..4bf3f2d8e906 100644 --- a/cpp/tests/unit_tests/kernels/CMakeLists.txt +++ b/cpp/tests/unit_tests/kernels/CMakeLists.txt @@ -23,8 +23,7 @@ add_tllm_gtest( tllm::kernel_logits tllm::runtime_buffers LABELS - "unit;kernels;logits;gpu" - REQUIRES_GPU) + "unit;kernels;logits;gpu") add_tllm_gtest( cascadeAttentionKernelTest OWNER @@ -34,8 +33,7 @@ add_tllm_gtest( LINK_LIBRARIES tllm::kernel_cascade_attention LABELS - "unit;kernels;cascade-attention;gpu" - REQUIRES_GPU) + "unit;kernels;cascade-attention;gpu") add_tllm_gtest( cascadeAttentionNumericsTest OWNER @@ -46,8 +44,7 @@ add_tllm_gtest( tllm::kernel_cascade_attention tllm::kernel_attention_decode LABELS - "unit;kernels;cascade-attention;gpu" - REQUIRES_GPU) + "unit;kernels;cascade-attention;gpu") macro(remove_compile_definition TARGET_NAME DEFINITION) get_target_property(DEFS ${TARGET_NAME} COMPILE_DEFINITIONS) @@ -69,8 +66,7 @@ add_tllm_gtest( tllm::kernel_quantization tllm::runtime_buffers LABELS - "unit;kernels;moe;gpu" - REQUIRES_GPU) + "unit;kernels;moe;gpu") # If we are using oss cutlass, build an explicit internal test if(USING_OSS_CUTLASS_MOE_GEMM) @@ -90,8 +86,7 @@ if(USING_OSS_CUTLASS_MOE_GEMM) tllm::kernel_quantization tllm::runtime_buffers LABELS - "unit;kernels;moe;gpu" - REQUIRES_GPU) + "unit;kernels;moe;gpu") remove_compile_definition(mixtureOfExpertsInternalTest USING_OSS_CUTLASS_MOE_GEMM) endif() @@ -106,8 +101,7 @@ add_tllm_gtest( tllm::kernel_rope tllm::runtime_buffers LABELS - "unit;kernels;rope;gpu" - REQUIRES_GPU) + "unit;kernels;rope;gpu") add_tllm_gtest( shiftKCacheKernelTest OWNER @@ -118,8 +112,7 @@ add_tllm_gtest( tllm::kernel_rope tllm::runtime_buffers LABELS - "unit;kernels;rope;gpu" - REQUIRES_GPU) + "unit;kernels;rope;gpu") add_tllm_gtest( smoothQuantKernelTest OWNER @@ -130,8 +123,7 @@ add_tllm_gtest( tllm::kernel_smooth_quant tllm::kernel_int8_gemm LABELS - "unit;kernels;smooth-quant;gpu" - REQUIRES_GPU) + "unit;kernels;smooth-quant;gpu") add_tllm_gtest( weightOnlyKernelTest OWNER @@ -142,8 +134,7 @@ add_tllm_gtest( tllm::kernel_weight_only tllm::kernel_weight_only_gemm LABELS - "unit;kernels;weight-only;gpu" - REQUIRES_GPU) + "unit;kernels;weight-only;gpu") add_tllm_gtest( mlaPreprocessTest OWNER @@ -154,8 +145,7 @@ add_tllm_gtest( tllm::kernel_mla tllm::runtime_buffers LABELS - "unit;kernels;mla;gpu" - REQUIRES_GPU) + "unit;kernels;mla;gpu") add_tllm_gtest( sparseAttentionKernelsTest OWNER @@ -166,8 +156,7 @@ add_tllm_gtest( tllm::kernel_sparse_attention tllm::runtime_buffers LABELS - "unit;kernels;sparse-attention;gpu" - REQUIRES_GPU) + "unit;kernels;sparse-attention;gpu") add_tllm_gtest( cudaCoreGemmKernelTest @@ -179,8 +168,7 @@ add_tllm_gtest( tllm::kernel_cuda_core_gemm CUDA::cublasLt LABELS - "unit;kernels;cuda-core-gemm;gpu" - REQUIRES_GPU) + "unit;kernels;cuda-core-gemm;gpu") add_tllm_gtest( mlaChunkedPrefillTest @@ -192,8 +180,7 @@ add_tllm_gtest( tllm::kernel_mla_chunked_prefill tllm::runtime_buffers LABELS - "unit;kernels;mla-chunked-prefill;gpu" - REQUIRES_GPU) + "unit;kernels;mla-chunked-prefill;gpu") add_tllm_gtest( fusedMoeCommKernelTest @@ -205,8 +192,7 @@ add_tllm_gtest( tllm::kernel_moe_communication Threads::Threads LABELS - "unit;kernels;moe-communication;gpu" - REQUIRES_GPU) + "unit;kernels;moe-communication;gpu") add_tllm_gtest( gemmSwigluRunnerTest @@ -218,8 +204,7 @@ add_tllm_gtest( tllm::kernel_gated_gemm LABELS "unit;kernels;gated-gemm;gpu" - NO_GTEST_MAIN - REQUIRES_GPU) + NO_GTEST_MAIN) add_executable(gemmSwigluKernelTestSm90Fp8 EXCLUDE_FROM_ALL fused_gated_gemm/gemmSwigluKernelTestSm90Fp8.cu) @@ -228,9 +213,8 @@ target_link_libraries(gemmSwigluKernelTestSm90Fp8 target_compile_features(gemmSwigluKernelTestSm90Fp8 PRIVATE cxx_std_20) add_test(NAME gemmSwigluKernelTestSm90Fp8 COMMAND gemmSwigluKernelTestSm90Fp8) set_tests_properties( - gemmSwigluKernelTestSm90Fp8 - PROPERTIES ENVIRONMENT "CUDA_MODULE_LOADING=LAZY" LABELS - "unit;kernels;gated-gemm;gpu" RESOURCE_LOCK gpu) + gemmSwigluKernelTestSm90Fp8 PROPERTIES ENVIRONMENT "CUDA_MODULE_LOADING=LAZY" + LABELS "unit;kernels;gated-gemm;gpu") add_dependencies(kernel-tests gemmSwigluKernelTestSm90Fp8) add_dependencies(google-tests gemmSwigluKernelTestSm90Fp8) @@ -268,8 +252,7 @@ add_tllm_gtest( tllm::runtime_buffers Python3::Python LABELS - "unit;kernels;moe-routing;gpu" - REQUIRES_GPU) + "unit;kernels;moe-routing;gpu") add_tllm_gtest( blockScaleMoeActivationTest @@ -281,8 +264,7 @@ add_tllm_gtest( tllm::kernel_moe_block_scale tllm::runtime_buffers LABELS - "unit;kernels;moe-block-scale;gpu" - REQUIRES_GPU) + "unit;kernels;moe-block-scale;gpu") add_tllm_gtest( blockScaleMoeFinalizeTest OWNER @@ -293,8 +275,7 @@ add_tllm_gtest( tllm::kernel_moe_block_scale tllm::runtime_buffers LABELS - "unit;kernels;moe-block-scale;gpu" - REQUIRES_GPU) + "unit;kernels;moe-block-scale;gpu") add_tllm_gtest( moeLoadBalanceKernelTest @@ -306,8 +287,7 @@ add_tllm_gtest( tllm::kernel_moe_load_balance Threads::Threads LABELS - "unit;kernels;moe-load-balance;gpu" - REQUIRES_GPU) + "unit;kernels;moe-load-balance;gpu") if(USING_OSS_CUTLASS_MOE_GEMM) add_tllm_gtest( @@ -319,8 +299,7 @@ if(USING_OSS_CUTLASS_MOE_GEMM) LINK_LIBRARIES tllm::kernel_moe_lora LABELS - "unit;kernels;moe-lora;gpu" - REQUIRES_GPU) + "unit;kernels;moe-lora;gpu") add_tllm_gtest( moeLoraProblemBuilderTest OWNER @@ -330,8 +309,7 @@ if(USING_OSS_CUTLASS_MOE_GEMM) LINK_LIBRARIES tllm::kernel_moe_lora LABELS - "unit;kernels;moe-lora;gpu" - REQUIRES_GPU) + "unit;kernels;moe-lora;gpu") add_tllm_gtest( moeLoraSlotExpandTest OWNER @@ -341,8 +319,7 @@ if(USING_OSS_CUTLASS_MOE_GEMM) LINK_LIBRARIES tllm::kernel_moe_lora LABELS - "unit;kernels;moe-lora;gpu" - REQUIRES_GPU) + "unit;kernels;moe-lora;gpu") endif() add_tllm_gtest( @@ -355,8 +332,7 @@ add_tllm_gtest( tllm::kernel_rope tllm::runtime_buffers LABELS - "unit;kernels;rope;sparse-kv-cache;gpu" - REQUIRES_GPU) + "unit;kernels;rope;sparse-kv-cache;gpu") add_tllm_gtest( prepareCustomMaskTest OWNER @@ -367,8 +343,7 @@ add_tllm_gtest( tllm::kernel_attention_mask tllm::runtime_buffers LABELS - "unit;kernels;attention-mask;gpu" - REQUIRES_GPU) + "unit;kernels;attention-mask;gpu") add_tllm_gtest( fmhaDsv4EpilogueFusionTest OWNER @@ -379,8 +354,7 @@ add_tllm_gtest( tllm::kernel_attention tllm::runtime_buffers LABELS - "unit;kernels;fmha;gpu" - REQUIRES_GPU) + "unit;kernels;fmha;gpu") add_tllm_gtest( nvfp4ColdPageKernelsTest @@ -392,5 +366,4 @@ add_tllm_gtest( tllm::kernel_nvfp4_cold_page tllm::kv_cache_host_memory LABELS - "unit;kernels;nvfp4-cold-page;gpu" - REQUIRES_GPU) + "unit;kernels;nvfp4-cold-page;gpu")