Skip to content

Commit 5d2851f

Browse files
Migrate internal changes
This synchronization round requires squashing a number of commits to avoid conflicts. Relevant commits messages are as follows: [docs] NFC: Add documentation for the compiler C++/C/Python APIs [cmake] NFC: Add CMP0177 policy [compiler] NFC: Make the extension API uniform across task types [compiler] Improve the compiler extension API [compiler] NFC: Fixup TensorRTToExecutable task [compiler] NFC: reduce the number of overloads in CompilerClient [compiler] Add mlir-tensorrt-compiler tool [compiler] Use a Pass option for configuring default backends in StablehloToExecutable [compiler] Eliminate some unnecessary complexity from compilation task management [cmake] Further improvements to the CMake build system [executor] Account for platform minimum alignment in allocation functions NFC: Add '--use-pep517' to 'pip install' commands [tensorrt] NFC: remove use of redundant CMake option [compiler] NFC: more improvements to the CMake build system [Integration] add nvfp4 Q-DQ into CI tests [tensorrt] Update support types for ops that expand to `tensorrt.shuffle` [plan] Fix a bug in `plan-remove-equivalent-buffer-results` pass. [compiler] NFC: remove unused include in CUDA dialect implementation [tensorrt] NFC: Fix unguarded CMake inclusion of TRT plugin test passes [tensorrt] NFC: fix unguarded inclusion in TRT plugin shape inference pass NFC: remove useless DEPENDS target from the 'mlir-tensorrt-opt' tool Fix uses of 'long' instead of 'int64_t' [cmake] More CMake fixes for fixing the TensorRT dependency NFC: various cleanup/improvements for the CMake build system [tensorrt] Add FP4 support [common] Update C++ TensorRT version check utilities to avoid assuming TRT headers are available [compiler] Fix phase ordering for CUDAToExecutor conversion [compiler] NFC: Separate Plan attributes and types into separate files [compiler] NFC: fix typo in naming of helper function [tensorrt] Update type support for `tensorrt.shuffle` op [executor] Drop "unpacked memref calling convention" [executor] Drop opaque ref type from executor [executor]: Fix static_assert in a template. [Compiler] Add donation argument support in `compiler` [compiler] Remove unnecessary canonicalization pass [executor] NFC: Separate Executor Attributes into a dedicated translation unit [compiler] Separate the attribute interface for bounds into a common library NFC: Rename '*ClusterKindAttr' to '*BackendAttr' NFC: Rename backend-configuration related attribute names in the Plan dialect NFC: Rename 'PlanClusterKindAttrInterface' to 'CompilerBackendAttrInterface' NFC: Deduplicate "region closure" utility NFC: update copybara configurations and add some additional documentation notes [executor][LuaAllocation]: Use llvm::stable_sort to preserve original order. [executor][TranslateToLua]: Add Lua variable allocation. [executor] Enable all Sol2 safety checks [compiler] Fix missing changes from recent LIT config change [compiler] Fix emitc integration test configuration issues [executor] Fix CMake build under minimal configuration [executor] Eliminate use of CUDA fp16, bf16, fp8 types/headers [executor] Make the Executor sub-project independently buildable [cmake] NFC: Fixup dependency provider CMake code [cmake] NFC: Improve CMake module code organization [cmake] Better validation of CMake options related to CUDA requirement NFC: Move TensorRTVersion.h utils header to common project Update lit.cfg.py to add SM features GitOrigin-RevId: fb878f289480850a0fef26762422f32ae313e134
1 parent 35eb233 commit 5d2851f

File tree

312 files changed

+11063
-5789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+11063
-5789
lines changed

mlir-tensorrt/CMakeLists.txt

Lines changed: 51 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
cmake_minimum_required(VERSION 3.25)
22
project(mlir-tensorrt LANGUAGES CXX C)
3+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/build_tools/cmake")
34

4-
# -------------------------------------------------
5-
# Set CMake behavior policies
6-
# -------------------------------------------------
7-
include(build_tools/cmake/CMakePolicy.cmake NO_POLICY_SCOPE)
5+
include(MTRTCMakePolicy NO_POLICY_SCOPE)
6+
7+
include(CMakeDependentOption)
8+
include(CMakePrintHelpers)
9+
include(MTRTCPM)
10+
include(MTRTDependencies)
11+
include(MTRTFeatures)
12+
include(AddMLIRTensorRT)
13+
include(Version.cmake)
14+
include(CMakeOptions.cmake)
815

916
# -------------------------------------------------
1017
# Package cache configuration
@@ -15,46 +22,6 @@ if(NOT CPM_SOURCE_CACHE)
1522
your build directory (for example '$PWD/.cache.cpm')")
1623
endif()
1724

18-
# -------------------------------------------------
19-
# Include utils/tools
20-
# -------------------------------------------------
21-
include(build_tools/cmake/CPM.cmake)
22-
include(build_tools/cmake/CompilationOptions.cmake)
23-
include(build_tools/cmake/Targets.cmake)
24-
include(build_tools/cmake/Dependencies.cmake)
25-
include(Version.cmake)
26-
27-
# -------------------------------------------------
28-
# Project Options / Configuration
29-
# -------------------------------------------------
30-
set(MLIR_TRT_FEATURE_FLAGS)
31-
macro(mtrt_option name)
32-
option(${name} ${ARGN})
33-
list(APPEND MLIR_TRT_FEATURE_FLAGS ${name})
34-
endmacro()
35-
36-
mtrt_option(MLIR_TRT_ENABLE_HLO "Whether to include stablehlo features" ON)
37-
mtrt_option(MLIR_TRT_ENABLE_ASSERTIONS "Enables assertions" ON)
38-
mtrt_option(MLIR_TRT_TARGET_TENSORRT "Enable exporting TensorRT dialect IR to a TensorRT engine" ON)
39-
mtrt_option(MLIR_TRT_TARGET_CPP "Enable exporting TensorRT dialect IR to C++ code that calls the TensorRT API" ON)
40-
mtrt_option(MLIR_TRT_ENABLE_PYTHON "Enable building the mlir_tensorrt_compiler python package." ON)
41-
mtrt_option(MLIR_TRT_ENABLE_NVTX "Enable NVTX tracing" ON)
42-
mtrt_option(MLIR_TRT_ENABLE_TESTING "Enable building optional tests" ON)
43-
mtrt_option(MLIR_TRT_TARGET_LUA "Enable translating MLIR to the Lua target" ON)
44-
mtrt_option(MLIR_TRT_ENABLE_EXECUTOR "Build the Executor dialect and MLIR-TensorRT Execution Engine" ON)
45-
mtrt_option(MLIR_TRT_ENABLE_NCCL "Enable the NCCL runtime module" ON)
46-
mtrt_option(MLIR_TRT_ENABLE_TORCH "Whether to include torch-mlir features" OFF)
47-
48-
set(MLIR_TRT_TENSORRT_DIR "" CACHE STRING "Path to TensorRT install directory")
49-
set(MLIR_TRT_DOWNLOAD_TENSORRT_VERSION "10.9" CACHE STRING
50-
"Version of TensorRT to download and use. It overrides MLIR_TRT_TENSORRT_DIR.")
51-
set(MLIR_TRT_PACKAGE_CACHE_DIR "" CACHE STRING "Directory where to cache downloaded C++ packages")
52-
set(MLIR_TRT_USE_LINKER "" CACHE STRING "Specify a linker to use (e.g. LLD); this is just an alias for LLVM_USE_LINKER")
53-
54-
# Configure dependent Executor options.
55-
set(MLIR_EXECUTOR_ENABLE_NCCL ${MLIR_TRT_ENABLE_NCCL} CACHE BOOL "" FORCE)
56-
set(MLIR_EXECUTOR_ENABLE_MPI ${MLIR_TRT_ENABLE_NCCL} CACHE BOOL "" FORCE)
57-
set(MLIR_EXECUTOR_ENABLE_CUBLAS ${MLIR_TRT_ENABLE_CUBLAS} CACHE BOOL "" FORCE)
5825

5926
# List of dialects to embed in the Python package. This is different between internal
6027
# and public versions of the code.
@@ -63,6 +30,25 @@ set(MLIR_TRT_PYTHON_UPSTREAM_DIALECTS_EMBED
6330
tensor
6431
)
6532

33+
# List of dialects to embed in the Python package. This is different between internal
34+
# and public versions of the code.
35+
set(MLIR_TRT_PYTHON_UPSTREAM_DIALECTS_EMBED
36+
affine arith bufferization builtin complex index func gpu math memref quant scf
37+
tensor linalg
38+
)
39+
40+
# Specifies whether we require CUDA at build time.
41+
set(MLIR_TRT_REQUIRES_CUDA FALSE)
42+
if(MLIR_TRT_TARGET_TENSORRT OR
43+
MLIR_TRT_ENABLE_CUBLAS OR
44+
MLIR_TRT_ENABLE_NCCL)
45+
set(MLIR_TRT_REQUIRES_CUDA TRUE)
46+
endif()
47+
48+
if(MLIR_TRT_REQUIRES_CUDA AND NOT MLIR_TRT_ENABLE_CUDA)
49+
message(FATAL_ERROR "CUDA is required but MLIR_TRT_ENABLE_CUDA is disabled")
50+
endif()
51+
6652
# -------------------------------------------------
6753
# Option validation
6854
# -------------------------------------------------
@@ -85,48 +71,27 @@ endif()
8571
# project.
8672
# Enables generation of compile_commands.json for clangd.
8773
if(PROJECT_IS_TOP_LEVEL)
88-
include(build_tools/cmake/CompilerCache.cmake)
74+
include(MTRTCompilerCache)
8975
mtrt_use_compiler_cache()
9076
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
77+
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
9178
endif()
9279

93-
# -------------------------------------------------
94-
# Option validation
95-
# -------------------------------------------------
96-
# Write out a header file containing convenience macros for each flag.
97-
function(mtrt_write_feature_flags_header)
98-
set(feature_flags_header
99-
"${CMAKE_CURRENT_BINARY_DIR}/include/mlir-tensorrt/Features.h")
100-
101-
# Generate the header at configure time
102-
file(WRITE "${feature_flags_header}" [[
103-
// Auto-generated feature macros, do not edit.
104-
#ifndef MLIR_TENSORRT_FEATURES_H
105-
#define MLIR_TENSORRT_FEATURES_H
106-
107-
]])
108-
109-
foreach(FEATURE IN LISTS MLIR_TRT_FEATURE_FLAGS)
110-
file(APPEND "${feature_flags_header}" "#ifdef ${FEATURE}\n")
111-
file(APPEND "${feature_flags_header}" "#define IF_${FEATURE}(code) do { code } while (0)\n")
112-
file(APPEND "${feature_flags_header}" "#else\n")
113-
file(APPEND "${feature_flags_header}" "#define IF_${FEATURE}(code) do {} while (0)\n")
114-
file(APPEND "${feature_flags_header}" "#endif // ${FEATURE}\n\n")
115-
endforeach()
116-
file(APPEND "${feature_flags_header}" "#endif // MLIR_TENSORRT_FEATURES_H\n")
117-
endfunction()
118-
119-
mtrt_write_feature_flags_header()
120-
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
80+
# The CUDA headers will trigger excessive "C++20 extensions warning" with
81+
# clang19+ in macro usage.
82+
include(CheckCXXCompilerFlag)
83+
check_cxx_compiler_flag("-Wc++20-extensions"
84+
CXX_SUPPORTS_C20_EXTENSIONS_FLAG)
85+
if(CXX_SUPPORTS_C20_EXTENSIONS_FLAG)
86+
add_compile_options(-Wno-c++20-extensions)
87+
endif()
12188

12289
# -------------------------------------------------
12390
# Setup LLVM/MLIR
12491
# -------------------------------------------------
12592
find_package(Python3 REQUIRED
12693
COMPONENTS Interpreter Development)
12794

128-
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
129-
13095
if(PROJECT_IS_TOP_LEVEL)
13196
set(MLIR_TRT_EXTERNAL_PROJECT_BUILD OFF)
13297
message("Building MLIR-TensorRT as a standalone project.")
@@ -168,12 +133,14 @@ include(AddLLVM)
168133
include(AddMLIR)
169134
include(HandleLLVMOptions)
170135

171-
find_package(CUDAToolkit)
172-
173136
# -------------------------------------------------
174137
# Dependencies
175138
# -------------------------------------------------
176139

140+
if(MLIR_TRT_REQUIRES_CUDA)
141+
find_package(CUDAToolkit REQUIRED)
142+
endif()
143+
177144
# Download Stablehlo if it isn't provided by a parent project.
178145
if(MLIR_TRT_ENABLE_HLO)
179146
find_package(Stablehlo REQUIRED)
@@ -192,8 +159,6 @@ if(MLIR_TRT_ENABLE_PYTHON)
192159
mlir_tensorrt_find_dlpack()
193160
endif()
194161

195-
find_package(MLIRTensorRTCommon REQUIRED)
196-
197162
#--------------------------------------------------
198163
# Diagnostics
199164
#--------------------------------------------------
@@ -222,6 +187,9 @@ include_directories(${MLIR_INCLUDE_DIRS})
222187
link_directories(${LLVM_BUILD_LIBRARY_DIR})
223188
add_definitions(${LLVM_DEFINITIONS} ${MLIR_TRT_DEFINITIONS})
224189

190+
mtrt_write_feature_flags_header()
191+
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
192+
225193
add_compile_options(-Wno-deprecated-declarations)
226194

227195
include(AddMLIRPython)
@@ -244,13 +212,7 @@ add_custom_target("mlir-tensorrt-doc")
244212
add_custom_target(check-all-mlir-tensorrt)
245213
add_custom_target(check-all-mlir-tensorrt-build-only)
246214

247-
if(MLIR_TRT_ENABLE_EXECUTOR)
248-
add_subdirectory(executor EXCLUDE_FROM_ALL)
249-
endif()
250-
251-
add_subdirectory(tensorrt EXCLUDE_FROM_ALL)
252-
include_directories(${CMAKE_CURRENT_LIST_DIR}/tensorrt/include)
253-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tensorrt/include)
254-
255-
add_subdirectory(compiler)
256-
add_subdirectory(integrations)
215+
add_subdirectory(common)
216+
foreach(project_name IN LISTS MLIR_TRT_ENABLE_PROJECTS)
217+
add_subdirectory(${project_name})
218+
endforeach()

mlir-tensorrt/CMakeOptions.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
mtrt_option(MLIR_TRT_ENABLE_HLO "Whether to include stablehlo features" ON)
2+
mtrt_option(MLIR_TRT_ENABLE_ASSERTIONS "Enables assertions" ON)
3+
mtrt_option(MLIR_TRT_TARGET_TENSORRT "Enable exporting TensorRT dialect IR to a TensorRT engine" ON)
4+
mtrt_option(MLIR_TRT_WITH_ASAN "Enable AddressSanitizer use" OFF)
5+
mtrt_option(MLIR_TRT_ENABLE_PYTHON "Enable building the mlir_tensorrt_compiler python package." ON)
6+
mtrt_option(MLIR_TRT_ENABLE_TESTING "Enable building optional tests" ON)
7+
mtrt_option(MLIR_TRT_ENABLE_TORCH "Whether to include torch-mlir features" OFF)
8+
mtrt_option(MLIR_TRT_ENABLE_NCCL "Enable the NCCL runtime module" OFF)
9+
mtrt_option(MLIR_TRT_ENABLE_CUBLAS "Enable CUBLAS in the executor" ON)
10+
mtrt_option(MLIR_TRT_ENABLE_CUDA "Enable the use of CUDA runtime" ON)
11+
mtrt_option(MLIR_TRT_ENABLE_MPI "Enable use of MPI in the runtime" ${MLIR_TRT_ENABLE_NCCL})
12+
13+
# The 'python' directory must come last because it actually instantiates
14+
# the compiler and runtime python packages in '<build-dir>/python_packages'
15+
# whereas the definition of the source groups belonging to those packages
16+
# are distributed across multiple sub-directories.
17+
set(MLIR_TRT_ENABLE_PROJECTS_DEFAULT
18+
executor tensorrt compiler integrations/python
19+
)
20+
21+
if(NOT MLIR_TRT_ENABLE_PYTHON)
22+
list(REMOVE_ITEM MLIR_TRT_ENABLE_PROJECTS_DEFAULT "integrations/python")
23+
endif()
24+
25+
set(MLIR_TRT_ENABLE_PROJECTS ${MLIR_TRT_ENABLE_PROJECTS_DEFAULT} CACHE INTERNAL "Projects to enable")
26+
27+
set(MLIR_TRT_TENSORRT_DIR "" CACHE STRING "Path to TensorRT install directory")
28+
set(MLIR_TRT_DOWNLOAD_TENSORRT_VERSION "10.12" CACHE STRING
29+
"Version of TensorRT to download and use. It overrides MLIR_TRT_TENSORRT_DIR.")
30+
set(MLIR_TRT_PACKAGE_CACHE_DIR "" CACHE STRING "Directory where to cache downloaded C++ packages")
31+
# We need this option since CMAKE_CUDA_ARCHITECTURES=native has some issues.
32+
set(MLIR_TRT_CUDA_ARCHITECTURES "detect" CACHE STRING
33+
"Equivalent to CMAKE_CUDA_ARCHITECTURES, but use \"detect\" to "
34+
"specify that the compute capability should be taken by querying the driver.")
35+
36+
if(MLIR_TRT_ENABLE_CUDA)
37+
set(MLIR_TRT_CUDA_TARGET "CUDA::cudart" CACHE INTERNAL "")
38+
else()
39+
set(MLIR_TRT_CUDA_TARGET "" CACHE INTERNAL "")
40+
endif()

0 commit comments

Comments
 (0)