Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
13 changes: 12 additions & 1 deletion .cmake-format.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
],
"kwargs": {
"SOURCE_LIST": "1",
"TARGET": "1",
"ARCHS": "+"
}
},
"tllm_add_cubin_archive_sources": {
"pargs": 2,
"flags": [
"IMPLICIT_FAMILY"
],
"kwargs": {
"SYMBOL_PREFIX": "1",
"SYMBOL_SUFFIX": "1",
"NAMESPACE": "+",
"ARCHS": "+"
}
}
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.xz filter=lfs diff=lfs merge=lfs -text
triton_backend/tools/gpt/input_data.json filter=lfs diff=lfs merge=lfs -text
*cubin.cpp filter=lfs diff=lfs merge=lfs -text
*.cubin.tar.zst filter=lfs diff=lfs merge=lfs -text
docs/source/blogs/media/tech_blog3_mla_absorb.png filter=lfs diff=lfs merge=lfs -text
tests/integration/test_input_files/*.png filter=lfs diff=lfs merge=lfs -text
tests/integration/test_input_files/*.jpg filter=lfs diff=lfs merge=lfs -text
Expand Down
16 changes: 16 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ include(sanitizers)

project(tensorrt_llm LANGUAGES CXX)

# Single source of truth for the inline ABI namespace. Read by both the C++ side
Comment thread
pengbowang-nv marked this conversation as resolved.
# (via tensorrt_llm/common/config.h's `#ifndef TRTLLM_ABI_NAMESPACE` guard) and
# the cubin INCBIN aggregator (cpp/cmake/modules/ tllm_cubin_archive.cmake bakes
# the same value into Itanium-mangled linker names). Override at configure time
# with `-DTRTLLM_ABI_NAMESPACE=_v2` to ship a parallel ABI version that won't
# collide at static-link time. The compile definition propagates to every C++ TU
# under this directory so the macro expansion stays in sync with the CMake
# variable.
set(TRTLLM_ABI_NAMESPACE
"_v1"
CACHE
STRING
"Inline namespace used to version the TRT-LLM ABI (see tensorrt_llm/common/config.h)."
)
add_compile_definitions(TRTLLM_ABI_NAMESPACE=${TRTLLM_ABI_NAMESPACE})

# Build options
option(BUILD_PYT "Build in PyTorch TorchScript class mode" ON)
option(BUILD_TESTS "Build Google tests" ON)
Expand Down
111 changes: 53 additions & 58 deletions cpp/cmake/modules/cuda_configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,26 @@ Functions

filter_source_cuda_architectures(
SOURCE_LIST <variable>
TARGET <target>
ARCHS <arch1> [<arch2> ...]
[IMPLICIT_FAMILY]
)

Removes source files targeting disabled CUDA architectures from the
source list. Files are matched by patterns like ``sm80``, ``sm_80``,
``SM80``, etc. in their filenames (for ``.cu`` and ``cubin.cpp`` files).
``SM80``, etc. in their filenames (for ``.cu``, ``.cubin.cpp``, and
``.cubin.tar.zst`` files).

``SOURCE_LIST <variable>``
Name of the variable containing the list of source files.
Modified in place to remove filtered files.

``TARGET <target>``
Target to add compile definitions to. If the target does not exist,
an INTERFACE library will be created.

``ARCHS <arch1> [<arch2> ...]``
List of architectures to check. May include ``f`` suffix.

``IMPLICIT_FAMILY``
When set, treats architectures >= ``CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY``
as implicitly family-enabled.

**Defined Macros:**

For each filtered architecture, a compile definition ``EXCLUDE_SM_<ARCH>``
(or ``EXCLUDE_SM_<ARCH>F`` for family architectures) is added to ``<target>``.

Example
^^^^^^^

Expand Down Expand Up @@ -202,11 +193,8 @@ Example
)
filter_source_cuda_architectures(
SOURCE_LIST KERNEL_SOURCES
TARGET my_kernel_interface
ARCHS 80 90 100
)
# ``my_kernel_interface`` target is created with definitions to exclude
# disabled architectures.

#]=======================================================================]

Expand Down Expand Up @@ -371,21 +359,20 @@ function(setup_cuda_architectures)
# -f suffix supported from Blackwell (100) starting from CUDA 12.9.
if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "12.9")
set(CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY 100)
set(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES
ON
PARENT_SCOPE)
set(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES ON)
else()
# -a provides no cross architecture compatibility, but luckily until CUDA
# 12.8 We have only one architecture within each family >= 9.
set(CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY 9999) # Effectively exclude all
# architectures
set(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES
OFF
PARENT_SCOPE)
set(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES OFF)
endif()
set(CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY
${CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY}
PARENT_SCOPE)
set(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES
${CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES}
PARENT_SCOPE)

# Compatibility low bounds: Always compile kernels for these architectures. 86
# is enabled to avoid perf regression when using 80 kernels.
Expand Down Expand Up @@ -446,8 +433,7 @@ function(setup_cuda_architectures)
103
120)
foreach(CUDA_ARCH IN LISTS ARCHITECTURES_WITH_KERNELS)
if(NOT ${CUDA_ARCH} IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG
AND NOT ${CUDA_ARCH} IN_LIST CMAKE_CUDA_ARCHITECTURES_NORMALIZED_LIST)
if(NOT ${CUDA_ARCH} IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
add_definitions("-DEXCLUDE_SM_${CUDA_ARCH}")
message(STATUS "Excluding SM ${CUDA_ARCH}")
endif()
Expand All @@ -468,6 +454,25 @@ function(setup_cuda_architectures)
endif()
endforeach()

set(ARCHITECTURE_FAMILIES_WITH_KERNELS 100 120)
foreach(FAMILY_ARCH IN LISTS ARCHITECTURE_FAMILIES_WITH_KERNELS)
set(FAMILY_ARCH_ENABLED FALSE)
if(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES)
if("${FAMILY_ARCH}f" IN_LIST CMAKE_CUDA_ARCHITECTURES_FAMILIES)
set(FAMILY_ARCH_ENABLED TRUE)
endif()
elseif(${FAMILY_ARCH} IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
# CUDA 12.8 cannot compile -f targets, but 100 and 120 are the only
# supported architectures in those families.
set(FAMILY_ARCH_ENABLED TRUE)
endif()

if(NOT FAMILY_ARCH_ENABLED)
add_definitions("-DEXCLUDE_SM_${FAMILY_ARCH}F")
message(STATUS "Excluding SM ${FAMILY_ARCH}F")
endif()
endforeach()

set(CMAKE_CUDA_ARCHITECTURES
${CMAKE_CUDA_ARCHITECTURES_NORMALIZED}
PARENT_SCOPE)
Expand Down Expand Up @@ -565,47 +570,32 @@ For each ARCH passed in:
but not "sm${ARCH}f" (case insensitive) will be excluded
Macro "EXCLUDE_SM_${ARCH}" will be defined on TARGET
- if ARCH is suffixed by f, NARCH is ARCH without f suffix:
if ARCH is not in CMAKE_CUDA_ARCHITECTURES_FAMILIES, source files containing
"sm${NARCH}f" (case insensitive) will be excluded
Macro "EXCLUDE_SM_${NARCH}F" will be defined on TARGET
if ARCH is not enabled as a family architecture or, for CUDA versions without
family target support, NARCH is not enabled as a numeric architecture, source
files containing "sm${NARCH}f" (case insensitive) will be excluded

- if IMPLICIT_FAMILY is set:
ARCH shall not suffixed by f.
- if ARCH >= CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY:
if "${ARCH}f" is not in CMAKE_CUDA_ARCHITECTURES_FAMILIES,
source files containing "sm${ARCH}" but not "sm${ARCH}a" (case insensitive) will be excluded
Macro "EXCLUDE_SM_${ARCH}" (no F) will be defined on TARGET
- else:
if "${ARCH}" is not in CMAKE_CUDA_ARCHITECTURES_ORIG,
source files containing "sm${ARCH}" (case insensitive) will be excluded
Macro "EXCLUDE_SM_${ARCH}" will be defined on TARGET
#]]
function(filter_source_cuda_architectures)
set(options IMPLICIT_FAMILY)
set(oneValueArgs SOURCE_LIST TARGET)
set(oneValueArgs SOURCE_LIST)
set(multiValueArgs ARCHS)

cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}"
"${multiValueArgs}")
set(SOURCES "${${arg_SOURCE_LIST}}")

if(NOT TARGET ${arg_TARGET})
add_library(${arg_TARGET} INTERFACE)
endif()

# Determine if target is INTERFACE library to use correct visibility
get_target_property(_target_type ${arg_TARGET} TYPE)
if(_target_type STREQUAL "INTERFACE_LIBRARY")
set(_compile_def_visibility INTERFACE)
else()
set(_compile_def_visibility PUBLIC)
endif()

foreach(ARCH IN LISTS arg_ARCHS)
set(SHOULD_FILTER FALSE)
set(MATCH_PATTERN "")
set(EXCLUDE_PATTERN "")
set(ARCH_FOR_DEFINE "")

if(NOT arg_IMPLICIT_FAMILY)
# Check if ARCH ends with 'f'
Expand All @@ -614,21 +604,31 @@ function(filter_source_cuda_architectures)
if(_has_f_suffix)
# ARCH is suffixed by 'f' (e.g., "100f")
set(BASE_ARCH "${CMAKE_MATCH_1}")
if(NOT "${ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_FAMILIES)
set(FAMILY_ARCH_ENABLED FALSE)
if(CMAKE_CUDA_ARCHITECTURES_HAS_FAMILIES)
if("${ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_FAMILIES)
set(FAMILY_ARCH_ENABLED TRUE)
endif()
elseif("${BASE_ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
set(FAMILY_ARCH_ENABLED TRUE)
endif()

if(NOT FAMILY_ARCH_ENABLED)
set(SHOULD_FILTER TRUE)
set(ARCH_FOR_DEFINE "${BASE_ARCH}F")
# Match "sm${BASE_ARCH}f" - straightforward match, no exclusion
# pattern needed
set(MATCH_PATTERN ".*[Ss][Mm]_?${BASE_ARCH}f.*(cubin\.cpp|\.cu)$")
set(MATCH_PATTERN
".*[Ss][Mm]_?${BASE_ARCH}f.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
endif()
else()
# ARCH is NOT suffixed by 'f' (e.g., "80")
if(NOT "${ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
set(SHOULD_FILTER TRUE)
set(ARCH_FOR_DEFINE "${ARCH}")
# Match "sm${ARCH}" but NOT "sm${ARCH}f"
set(MATCH_PATTERN ".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu)$")
set(EXCLUDE_PATTERN ".*[Ss][Mm]_?${ARCH}f.*(cubin\.cpp|\.cu)$")
set(MATCH_PATTERN
".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
set(EXCLUDE_PATTERN
".*[Ss][Mm]_?${ARCH}f.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
endif()
endif()
else()
Expand All @@ -637,18 +637,19 @@ function(filter_source_cuda_architectures)
# ARCH >= CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY
if(NOT "${ARCH}f" IN_LIST CMAKE_CUDA_ARCHITECTURES_FAMILIES)
set(SHOULD_FILTER TRUE)
set(ARCH_FOR_DEFINE "${ARCH}")
# Match "sm${ARCH}" but NOT "sm${ARCH}a"
set(MATCH_PATTERN ".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu)$")
set(EXCLUDE_PATTERN ".*[Ss][Mm]_?${ARCH}a.*(cubin\.cpp|\.cu)$")
set(MATCH_PATTERN
".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
set(EXCLUDE_PATTERN
".*[Ss][Mm]_?${ARCH}a.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
endif()
else()
# ARCH < CMAKE_CUDA_MIN_ARCHITECTURE_HAS_FAMILY
if(NOT "${ARCH}" IN_LIST CMAKE_CUDA_ARCHITECTURES_ORIG)
set(SHOULD_FILTER TRUE)
set(ARCH_FOR_DEFINE "${ARCH}")
# Match "sm${ARCH}" - no exclusion pattern needed
set(MATCH_PATTERN ".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu)$")
set(MATCH_PATTERN
".*[Ss][Mm]_?${ARCH}.*(cubin\.cpp|\.cu|cubin\.tar\.zst)$")
endif()
endif()
endif()
Expand Down Expand Up @@ -683,12 +684,6 @@ function(filter_source_cuda_architectures)
if(SOURCES_FILTERED)
list(REMOVE_ITEM SOURCES ${SOURCES_FILTERED})
endif()

# Add compile definition to target
target_compile_definitions(
${arg_TARGET}
${_compile_def_visibility}
"EXCLUDE_SM_${ARCH_FOR_DEFINE}")
endif()
endforeach()

Expand Down
Loading
Loading