mirror of
https://github.com/NVIDIA/TensorRT-LLM.git
synced 2026-02-16 07:53:55 +08:00
[TRTLLM-10793][feat] Add BOLT compatible build flags for further experimental usage. (#11297)
Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com>
This commit is contained in:
parent
58165d5394
commit
632c039aea
@ -369,6 +369,29 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-relax")
|
||||
endif()
|
||||
|
||||
# ==== BOLT Compatible Flags ====
|
||||
# These flags enable LLVM BOLT binary compatible:
|
||||
# -fno-reorder-blocks-and-partition: Prevents compiler from splitting hot/cold
|
||||
# blocks -fno-plt: Removes PLT stubs for additional performance
|
||||
# -Wl,--emit-relocs (or -Wl,-q): Preserves relocation info for BOLT Note:
|
||||
# Binaries should NOT be stripped for BOLT to work Usage: cmake
|
||||
# -DENABLE_BOLT_COMPATIBLE=ON ...
|
||||
option(ENABLE_BOLT_COMPATIBLE "Enable BOLT-compatible build flags" OFF)
|
||||
if(ENABLE_BOLT_COMPATIBLE AND NOT WIN32)
|
||||
message(STATUS "BOLT compatible flags enabled")
|
||||
# Compiler flags for C/C++
|
||||
add_compile_options(-fno-reorder-blocks-and-partition -fno-plt)
|
||||
# Linker flags - applies to shared, module, and executable targets
|
||||
add_link_options(-Wl,--emit-relocs)
|
||||
# Disable stripping - required for BOLT (affects pybind11 POST_BUILD strip)
|
||||
set(CMAKE_STRIP
|
||||
""
|
||||
CACHE STRING "Disabled for BOLT compatibility" FORCE)
|
||||
message(STATUS "BOLT: Disabled CMAKE_STRIP to prevent binary stripping")
|
||||
endif()
|
||||
# Note: For nanobind modules, use NOSTRIP option in nanobind_add_module()
|
||||
# ==== End BOLT Compatible Flags ====
|
||||
|
||||
# Disable deprecated declarations warnings
|
||||
if(NOT WIN32)
|
||||
set(CMAKE_CXX_FLAGS "-Wno-deprecated-declarations ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
@ -67,7 +67,14 @@ if(NIXL_ENABLED OR MOONCAKE_ENABLED)
|
||||
set(AGENT_BINDING_SOURCES "")
|
||||
list(APPEND AGENT_BINDING_SOURCES agentBindings.cpp)
|
||||
|
||||
nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET} ${AGENT_BINDING_SOURCES})
|
||||
# NOSTRIP: Disable stripping for BOLT compatibility (requires --emit-relocs)
|
||||
if(ENABLE_BOLT_COMPATIBLE)
|
||||
nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET} NOSTRIP
|
||||
${AGENT_BINDING_SOURCES})
|
||||
else()
|
||||
nanobind_add_module(${TRANSFER_AGENT_BINDING_TARGET}
|
||||
${AGENT_BINDING_SOURCES})
|
||||
endif()
|
||||
message(STATUS "Building tensorrt_llm_transfer_agent_binding with nanobind")
|
||||
|
||||
target_compile_options(${TRANSFER_AGENT_BINDING_TARGET} PRIVATE -Wno-error)
|
||||
|
||||
@ -29,7 +29,12 @@ set(SRCS
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
nanobind_add_module(${TRTLLM_NB_MODULE} ${SRCS})
|
||||
# NOSTRIP: Disable stripping for BOLT compatibility (requires --emit-relocs)
|
||||
if(ENABLE_BOLT_COMPATIBLE)
|
||||
nanobind_add_module(${TRTLLM_NB_MODULE} NOSTRIP ${SRCS})
|
||||
else()
|
||||
nanobind_add_module(${TRTLLM_NB_MODULE} ${SRCS})
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${TRTLLM_NB_MODULE} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
@ -598,6 +598,18 @@ def main(*,
|
||||
if nvrtc_dynamic_linking:
|
||||
cmake_def_args.append(f"-DNVRTC_DYNAMIC_LINKING=ON")
|
||||
|
||||
# BOLT compatibility: Force dynamic linking for NVIDIA libraries
|
||||
# Static NVIDIA libraries (libnvrtc_static.a, etc.) lack --emit-relocs,
|
||||
# which BOLT requires for proper binary optimization.
|
||||
bolt_enabled = any("ENABLE_BOLT_COMPATIBLE=ON" in var
|
||||
for var in extra_cmake_vars)
|
||||
if bolt_enabled:
|
||||
if not nvrtc_dynamic_linking:
|
||||
cmake_def_args.append("-DNVRTC_DYNAMIC_LINKING=ON")
|
||||
print(
|
||||
"-- BOLT: Forcing NVRTC_DYNAMIC_LINKING=ON (static NVIDIA libs lack relocations)"
|
||||
)
|
||||
|
||||
targets = ["tensorrt_llm", "nvinfer_plugin_tensorrt_llm"]
|
||||
|
||||
if cpp_only:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user