Skip to content

Commit bb9f64b

Browse files
Merge branch 'main' into lluo/wheel_release
2 parents dc883d7 + e3a2350 commit bb9f64b

File tree

19 files changed

+225
-96
lines changed

19 files changed

+225
-96
lines changed

mlir-tensorrt/.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.td

mlir-tensorrt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include(MTRTCMakePolicy NO_POLICY_SCOPE)
77
include(CMakeDependentOption)
88
include(CMakePrintHelpers)
99
include(MTRTCPM)
10+
include(MTRTCMakeExtras)
1011
include(MTRTDependencies)
1112
include(MTRTFeatures)
1213
include(AddMLIRTensorRT)

mlir-tensorrt/CMakeOptions.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ mtrt_option(MLIR_TRT_RELATIVE_DEBUG_PATHS
3939
# whereas the definition of the source groups belonging to those packages
4040
# are distributed across multiple sub-directories.
4141
set(MLIR_TRT_ENABLE_PROJECTS_DEFAULT
42-
executor tensorrt compiler
42+
executor tensorrt
4343
)
4444

45+
list(APPEND MLIR_TRT_ENABLE_PROJECTS_DEFAULT "compiler")
46+
4547
if(MLIR_TRT_ENABLE_PYTHON)
4648
list(APPEND MLIR_TRT_ENABLE_PROJECTS_DEFAULT "integrations/python")
4749
endif()
@@ -74,3 +76,4 @@ if(MLIR_TRT_ENABLE_NCCL)
7476
else()
7577
set(MLIR_TRT_NCCL_TARGET "" CACHE INTERNAL "")
7678
endif()
79+

mlir-tensorrt/Version.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ set(MLIR_TENSORRT_VERSION_MINOR "4")
33
set(MLIR_TENSORRT_VERSION_PATCH "3")
44
set(MLIR_TENSORRT_VERSION
55
"${MLIR_TENSORRT_VERSION_MAJOR}.${MLIR_TENSORRT_VERSION_MINOR}.${MLIR_TENSORRT_VERSION_PATCH}")
6+
7+
# The source release script replaces the empty string with a actual
8+
# hash, so don't change the default here.
9+
set(MLIR_TENSORRT_GIT_HASH "")
10+
11+
set(CPACK_PACKAGE_VERSION_MAJOR ${MLIR_TENSORRT_VERSION_MAJOR})
12+
set(CPACK_PACKAGE_VERSION_MINOR ${MLIR_TENSORRT_VERSION_MINOR})
13+
set(CPACK_PACKAGE_VERSION_PATCH ${MLIR_TENSORRT_VERSION_PATCH})

mlir-tensorrt/build_tools/cmake/MTRTCommonFunctions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ function(mtrt_add_project_library name)
332332
add_mlir_library(${name} ${lib_type_args} DISABLE_INSTALL EXCLUDE_FROM_LIBMLIR ${ARG_UNPARSED_ARGUMENTS})
333333
endif()
334334

335+
mtrt_apply_extra_check_options("${name}")
336+
335337
if(ARG_MLIR_LIBS)
336338
list(POP_FRONT ARG_MLIR_LIBS VISIBILITY)
337339
mtrt_target_link_mlir_libraries(${name} ${VISIBILITY} ${ARG_MLIR_LIBS})
Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
1+
2+
# Force-set internal cache variable "MLIR_TRT_APPLY_EXTRA_CHECKS" to
3+
# the result of the expression
4+
# (MLIR_TRT_ENABLE_EXTRA_CHECKS AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")).
5+
# This is done to avoid repeated checks when we populate target compilation options.
6+
set(MLIR_TRT_APPLY_EXTRA_CHECKS FALSE CACHE INTERNAL "")
7+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND MLIR_TRT_ENABLE_EXTRA_CHECKS)
8+
set(MLIR_TRT_APPLY_EXTRA_CHECKS TRUE CACHE INTERNAL "")
9+
endif()
10+
111
if(MLIR_TRT_ENABLE_WERROR)
212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
313
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
414
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wno-error")
515
endif()
616

7-
function(append_c_cxx_flags)
17+
# ------------------------------------------------------------------------------
18+
# Applies additional compilation options to a C/CXX library or executable
19+
# target. This only has an effect if MLIR_TRT_ENABLE_EXTRA_CHECKS is ON.
20+
# ------------------------------------------------------------------------------
21+
22+
macro(mtrt_apply_extra_checks_to_target_helper target)
23+
target_compile_options(${target} PRIVATE
24+
-Wmissing-declarations
25+
-Wmissing-prototypes
26+
-Wunused
27+
-fstrict-flex-arrays=3
28+
)
29+
endmacro()
30+
31+
macro(mtrt_apply_extra_check_options target)
32+
if(MLIR_TRT_APPLY_EXTRA_CHECKS)
33+
if(TARGET "obj.${target}")
34+
mtrt_apply_extra_checks_to_target_helper("obj.${target}")
35+
else()
36+
mtrt_apply_extra_checks_to_target_helper("${target}")
37+
endif()
38+
endif()
39+
endmacro()
40+
41+
# ------------------------------------------------------------------------------
42+
# Updates global C/CXX library or executable compilation flags.
43+
# This only has an effect if MLIR_TRT_ENABLE_EXTRA_CHECKS is ON.
44+
#
45+
# Some flags enable additional warnings, others may enable additional runtime
46+
# safety or preconditions checks.
47+
#
48+
# For a description of each flag, see the below reference:
49+
# https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
50+
# ------------------------------------------------------------------------------
51+
function(mtrt_update_global_c_cxx_flags)
852
string(JOIN " " flags ${ARGN})
953
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flags}" PARENT_SCOPE)
1054
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flags}" PARENT_SCOPE)
1155
endfunction()
1256

13-
# Enable additional warnings and runtime checks recommended
14-
# by https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
15-
if(MLIR_TRT_ENABLE_EXTRA_CHECKS AND
16-
(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
57+
if(MLIR_TRT_APPLY_EXTRA_CHECKS)
1758
# FORTIFY_SOURCE=3 requires O1 or higher.
18-
# GCC has default FORTIFY_SOURCE=2.
19-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
20-
(NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
59+
# GCC has default FORTIFY_SOURCE=2 and would require `-U_FORTIFY_SOURCE`
60+
# to change the value, so we just set it to 3 when using clang.
61+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
62+
AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2163
add_compile_definitions(
2264
_FORTIFY_SOURCE=3
2365
)
2466
endif()
2567

26-
# Note: '-D_GLIBCXX_ASSERTIONS' already added by
27-
# the 'HandleLLVMOptions'.
28-
29-
append_c_cxx_flags(
30-
# Enforce that all global functions have declarations. This catches
31-
# missing `static` qualifiers on functions which are intended to be TU-local.
32-
-Wmissing-declarations
33-
-Wmissing-prototypes
34-
-Wunused
68+
mtrt_update_global_c_cxx_flags(
3569
# Make template instantiation errors more readable.
3670
-fdiagnostics-show-template-tree
3771
# Enable better bounds checking for trailing array members.
38-
# Value is 0 to 3, with 3 being the most strict. LLVM has some code that
39-
# only allows us to use 1 here.
4072
-fstrict-flex-arrays=1
4173
# Enable runtime checks for variable-size stack allocation validity.
4274
-fstack-clash-protection
@@ -48,25 +80,61 @@ if(MLIR_TRT_ENABLE_EXTRA_CHECKS AND
4880
-Werror=int-conversion
4981
)
5082

51-
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR
52-
CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
53-
append_c_cxx_flags(
83+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
84+
mtrt_update_global_c_cxx_flags(
5485
-fcf-protection=full
55-
)
56-
endif()
57-
58-
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
59-
append_c_cxx_flags(
6086
-Wself-assign
6187
)
6288
endif()
6389
endif()
6490

65-
# The CUDA headers will trigger excessive "C++20 extensions warning" with
66-
# clang19+ in macro usage.
67-
include(CheckCXXCompilerFlag)
68-
check_cxx_compiler_flag("-Wc++20-extensions"
69-
CXX_SUPPORTS_C20_EXTENSIONS_FLAG)
70-
if(CXX_SUPPORTS_C20_EXTENSIONS_FLAG)
71-
add_compile_options(-Wno-c++20-extensions)
91+
# This ensures that `__FILE__` in log printing expands to a relative path and file paths
92+
# in debug info will expand relative to the source or binary directories.
93+
#
94+
#
95+
# It adds the following global compilation flag:
96+
# '-fno-canonical-prefixes'
97+
# '-ffile-prefix-map=[project_src_root]=.'
98+
# '-fdebug-prefix-map=[project_src_root]=.'
99+
# In addition, this flag is added if the build directory is not a subdirectory of the source directory:
100+
# '-ffile-prefix-map=[project_binary_root]=build'.
101+
# '-fdebug-prefix-map=[project_binary_root]=build'.
102+
#
103+
# This is only applied if the project is the top-level project and MLIR_TRT_RELATIVE_DEBUG_PATHS is ON.
104+
function(mtrt_apply_relative_path_options)
105+
if(NOT COMMAND mtrt_append_compiler_flag_if_supported)
106+
message(FATAL_ERROR "MTRTCompilationOptions must be included after MTRTCMakeExtras")
107+
endif()
108+
109+
# In CMake, you can't know where the "cmake" command is invoked from, so we
110+
# just assume that we want make paths relative to the source directory.
111+
set(relative_src ".")
112+
113+
# The following checks if the source directory is a prefix of the binary directory.
114+
cmake_path(IS_PREFIX CMAKE_SOURCE_DIR "${CMAKE_BINARY_DIR}" src_dir_is_prefix_of_bin_dir)
115+
116+
set(debug_remaps "-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.")
117+
set(file_remaps "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")
118+
if(src_dir_is_prefix_of_bin_dir)
119+
set(debug_remaps "${debug_remaps} -fdebug-prefix-map=${CMAKE_BINARY_DIR}=build")
120+
set(file_remaps "${file_remaps} -ffile-prefix-map=${CMAKE_BINARY_DIR}=build")
121+
endif()
122+
123+
mtrt_append_compiler_flag_if_supported(
124+
CHECK "-fdebug-prefix-map=foo=bar"
125+
APPEND "${debug_remaps}"
126+
)
127+
128+
mtrt_append_compiler_flag_if_supported(
129+
CHECK "-ffile-prefix-map=foo=bar"
130+
APPEND "${file_remaps}"
131+
)
132+
mtrt_append_compiler_flag_if_supported(
133+
CHECK "-no-canonical-prefixes"
134+
APPEND "-no-canonical-prefixes"
135+
)
136+
endfunction()
137+
138+
if(PROJECT_IS_TOP_LEVEL AND MLIR_TRT_RELATIVE_DEBUG_PATHS)
139+
mtrt_apply_relative_path_options()
72140
endif()

mlir-tensorrt/build_tools/cmake/MTRTRelativeDebugPaths.cmake

Lines changed: 0 additions & 33 deletions
This file was deleted.

mlir-tensorrt/compiler/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ mtrt_add_project_targets(MLIRTensorRT
5050
MLIRTransformDialectTransforms
5151
)
5252

53-
5453
add_subdirectory(include)
5554
add_subdirectory(lib)
5655
add_subdirectory(test)
5756

58-
5957
# Tools must be sequenced after tests.
6058
add_subdirectory(tools)
6159

@@ -69,7 +67,6 @@ set(MTRT_COMPILER_HEADER_DIRS
6967
"${PROJECT_BINARY_DIR}/include/mlir-tensorrt"
7068
)
7169

72-
7370
mtrt_add_header_installation_components(mtrt-headers
7471
DIRECTORIES
7572
${MTRT_COMPILER_HEADER_DIRS}

mlir-tensorrt/compiler/include/mlir-tensorrt/Conversion/Passes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def ConvertStablehloToPlanPass : Pass<"convert-stablehlo-to-plan", "::mlir::Modu
4141
calls.
4242
}];
4343
let dependentDialects = [
44+
"::mlir::cf::ControlFlowDialect",
4445
"::mlir::plan::PlanDialect",
4546
"::mlir::executor::ExecutorDialect",
4647
"::mlir::tensor::TensorDialect"

mlir-tensorrt/compiler/lib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_subdirectory(Analysis)
22

3-
43
add_subdirectory(Utils)
54
add_subdirectory(Interfaces)
65
add_subdirectory(Dialect)

0 commit comments

Comments
 (0)