[TRTLLM-4770][feat] Enhance cpp executor cmake to listen to ENABLE_MU… (#5104)

...LTI_DEVICE

Signed-off-by: William Tambellini <wtambellini@sdl.com>
This commit is contained in:
William Tambellini 2025-07-10 19:59:44 -07:00 committed by GitHub
parent 0385f89abc
commit fbb4cc7379
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 20 deletions

View File

@ -22,11 +22,20 @@ if(NOT TRTLLM_BUILD_DIR)
set(TRTLLM_BUILD_DIR "${TRTLLM_DIR}/cpp/build")
endif()
set(TRTLLM_LIB_PATH "${TRTLLM_BUILD_DIR}/tensorrt_llm/libtensorrt_llm.so")
if(NOT EXISTS ${TRTLLM_LIB_PATH})
message(FATAL_ERROR "Cannot find ${TRTLLM_LIB_PATH}")
endif()
set(TRTLLM_PLUGIN_PATH
"${TRTLLM_BUILD_DIR}/tensorrt_llm/plugins/libnvinfer_plugin_tensorrt_llm.so"
)
set(TRTLLM_INCLUDE_DIR "${TRTLLM_DIR}/cpp/include")
option(
ENABLE_MULTI_DEVICE
"Enable multi device/instance examples building (requires MPI headers/libs)"
ON)
# Determine CXX11 ABI compatibility
execute_process(
COMMAND bash -c "nm -f posix -D ${TRTLLM_LIB_PATH} | grep __cxx11"
@ -47,8 +56,13 @@ set(CMAKE_VERBOSE_MAKEFILE 1)
# Define project name
project(executorExamples)
# Compile options
set(CMAKE_CXX_FLAGS "-Wall -pthread -lstdc++ -DENABLE_MULTI_DEVICE=1")
# Compile options $<BOOL:${ENABLE_MULTI_DEVICE}> ?
if(ENABLE_MULTI_DEVICE)
set(EMD 1)
else()
set(EMD 0)
endif()
set(CMAKE_CXX_FLAGS "-Wall -pthread -lstdc++ -DENABLE_MULTI_DEVICE=${EMD} ")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_BUILD_TYPE release)
@ -120,23 +134,25 @@ target_link_libraries(executorExampleAdvanced nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts)
# MultiInstance
if(ENABLE_MULTI_DEVICE)
find_package(MPI REQUIRED)
message(STATUS "Using MPI_C_INCLUDE_DIRS: ${MPI_C_INCLUDE_DIRS}")
message(STATUS "Using MPI_C_LIBRARIES: ${MPI_C_LIBRARIES}")
include_directories(${MPI_C_INCLUDE_DIRS})
find_package(MPI REQUIRED)
message(STATUS "Using MPI_C_INCLUDE_DIRS: ${MPI_C_INCLUDE_DIRS}")
message(STATUS "Using MPI_C_LIBRARIES: ${MPI_C_LIBRARIES}")
include_directories(${MPI_C_INCLUDE_DIRS})
add_executable(executorExampleAdvancedMultiInstances
executorExampleAdvancedMultiInstances.cpp)
target_link_libraries(
executorExampleAdvancedMultiInstances nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts ${MPI_C_LIBRARIES})
add_executable(executorExampleAdvancedMultiInstances
executorExampleAdvancedMultiInstances.cpp)
target_link_libraries(
executorExampleAdvancedMultiInstances nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts ${MPI_C_LIBRARIES})
# FastLogits
add_executable(executorExampleFastLogits executorExampleFastLogits.cpp)
target_link_libraries(executorExampleFastLogits nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts ${MPI_C_LIBRARIES})
# FastLogits
add_executable(executorExampleFastLogits executorExampleFastLogits.cpp)
target_link_libraries(executorExampleFastLogits nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts ${MPI_C_LIBRARIES})
add_executable(executorExampleDisaggregated executorExampleDisaggregated.cpp)
target_link_libraries(executorExampleDisaggregated nvinfer_plugin_tensorrt_llm
cxxopts::cxxopts ${MPI_C_LIBRARIES})
add_executable(executorExampleDisaggregated executorExampleDisaggregated.cpp)
target_link_libraries(
executorExampleDisaggregated nvinfer_plugin_tensorrt_llm cxxopts::cxxopts
${MPI_C_LIBRARIES})
endif()

View File

@ -21,7 +21,7 @@ def working_directory(path: PathLike):
def build_cpp_examples(build_dir: PathLike, trt_dir: PathLike,
loglevel: int) -> None:
enable_multi_device: str, loglevel: int) -> None:
logging.basicConfig(level=loglevel,
format='%(asctime)s - %(levelname)s - %(message)s')
# Convert input paths to pathlib.Path objects
@ -52,6 +52,7 @@ def build_cpp_examples(build_dir: PathLike, trt_dir: PathLike,
'-B',
'.',
f'-DTensorRT_ROOT={cmake_parse(trt_dir)}',
f'-DENABLE_MULTI_DEVICE={enable_multi_device}',
] + generator
logging.info(f"Executing {generate_command}")
subprocess.run(generate_command, check=True)
@ -70,6 +71,9 @@ if __name__ == '__main__':
parser.add_argument('--trt-dir',
default='/usr/local/tensorrt',
help='TensorRT directory path')
parser.add_argument('--enable-multi-device',
default='ON',
help='Enable multi device support (requires MPI)')
parser.add_argument('-v',
'--verbose',
help="verbose",