Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
158 lines (142 loc) · 6.02 KB
/
Copy pathCMakeLists.txt
File metadata and controls
158 lines (142 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.23)
project(mlvc_cpp VERSION 0.1.0 LANGUAGES C CXX)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CTest)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64|AMD64)$")
message(FATAL_ERROR "mlvc.cpp supports Linux x86_64 NVIDIA GPU releases only")
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
option(MLVC_ENABLE_IPO "Enable interprocedural optimization in Release builds" ON)
option(MLVC_EMBED_MODELS
"Embed canonical model bundles in driver-cubin builds" ON)
option(MLVC_WARNINGS_AS_ERRORS "Treat project warnings as errors" OFF)
option(MLVC_ENABLE_SANITIZERS
"Enable AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
set(MLVC_SELECTED_BACKEND "onnxruntime" CACHE STRING
"Inference backend: onnxruntime, libtorch, tensorrt, or driver_cubin")
set_property(CACHE MLVC_SELECTED_BACKEND PROPERTY STRINGS
onnxruntime libtorch tensorrt driver_cubin)
set(MLVC_TEST_ASSETS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/models/fixtures" CACHE PATH
"Local MLVC model/reference fixtures used by tests")
set(MLVC_MODEL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/models/canonical" CACHE PATH
"Canonical model bundle root")
set(MLVC_TEST_ENGINE_CACHE_DIR "" CACHE PATH
"Optional TensorRT engine-cache root used by conformance tests")
set(_mlvc_valid_backends onnxruntime libtorch tensorrt driver_cubin)
if(NOT MLVC_SELECTED_BACKEND IN_LIST _mlvc_valid_backends)
message(FATAL_ERROR
"MLVC_SELECTED_BACKEND must be one of: "
"onnxruntime, libtorch, tensorrt, driver_cubin")
endif()
message(STATUS "MLVC selected backend: ${MLVC_SELECTED_BACKEND}")
include(CheckIPOSupported)
if(MLVC_ENABLE_IPO)
check_ipo_supported(LANGUAGES CXX
RESULT MLVC_IPO_SUPPORTED OUTPUT MLVC_IPO_ERROR)
if(NOT MLVC_IPO_SUPPORTED)
message(WARNING "IPO is unavailable: ${MLVC_IPO_ERROR}")
endif()
else()
set(MLVC_IPO_SUPPORTED OFF)
endif()
function(mlvc_enable_ipo target)
if(MLVC_ENABLE_IPO AND MLVC_IPO_SUPPORTED AND TARGET "${target}")
set_property(TARGET "${target}"
PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
endif()
endfunction()
add_library(mlvc_project_options INTERFACE)
target_compile_options(mlvc_project_options INTERFACE
"$<$<COMPILE_LANG_AND_ID:C,GNU,Clang,AppleClang>:-Wall;-Wextra;-Wpedantic;-Wformat=2;-Wshadow;-Wundef>"
"$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Wall;-Wextra;-Wpedantic;-Wformat=2;-Wshadow;-Wundef>")
if(MLVC_WARNINGS_AS_ERRORS)
target_compile_options(mlvc_project_options INTERFACE
"$<$<COMPILE_LANG_AND_ID:C,GNU,Clang,AppleClang>:-Werror>"
"$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-Werror>")
endif()
if(MLVC_ENABLE_SANITIZERS)
if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" OR
NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(FATAL_ERROR "MLVC sanitizers require GCC or Clang")
endif()
target_compile_options(mlvc_project_options INTERFACE
-fno-omit-frame-pointer -fno-sanitize-recover=all
-fsanitize=address,undefined)
target_link_options(mlvc_project_options INTERFACE
-fno-sanitize-recover=all -fsanitize=address,undefined)
endif()
function(mlvc_configure_target target)
target_link_libraries("${target}" PRIVATE mlvc_project_options)
endfunction()
include(cmake/Dependencies.cmake)
add_subdirectory(core)
add_subdirectory(runtime)
add_subdirectory(backends)
add_subdirectory(codec)
add_subdirectory(tools)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
DESTINATION "share/licenses/mlvc_cpp")
# Export only the stable C ABI. Core, runtime, backend, driver, CUTLASS, and
# AOT headers are implementation details and are intentionally not installed.
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/public/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/mlvc_codecConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/mlvc_codecConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mlvc_codec")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/mlvc_codecConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(EXPORT mlvc_codecTargets
FILE mlvc_codecTargets.cmake
NAMESPACE mlvc::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mlvc_codec")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/mlvc_codecConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/mlvc_codecConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/mlvc_codec")
if(MLVC_SELECTED_BACKEND STREQUAL "onnxruntime")
file(GLOB _backend_license_files
"${ONNXRUNTIME_ROOT}/LICENSE*"
"${ONNXRUNTIME_ROOT}/*Notice*"
"${ONNXRUNTIME_ROOT}/*NOTICE*")
if(_backend_license_files)
install(FILES ${_backend_license_files}
DESTINATION "share/licenses/onnxruntime")
endif()
elseif(MLVC_SELECTED_BACKEND STREQUAL "libtorch")
file(GLOB _backend_license_files
"${LIBTORCH_ROOT}/LICENSE*"
"${LIBTORCH_ROOT}/*Notice*"
"${LIBTORCH_ROOT}/*NOTICE*")
if(_backend_license_files)
install(FILES ${_backend_license_files}
DESTINATION "share/licenses/libtorch")
endif()
elseif(MLVC_SELECTED_BACKEND STREQUAL "tensorrt")
if(EXISTS "/usr/share/doc/libnvinfer11/copyright")
install(FILES "/usr/share/doc/libnvinfer11/copyright"
DESTINATION "share/licenses/tensorrt"
RENAME "libnvinfer11.txt")
endif()
if(EXISTS "/usr/share/doc/libnvonnxparsers11/copyright")
install(FILES "/usr/share/doc/libnvonnxparsers11/copyright"
DESTINATION "share/licenses/tensorrt"
RENAME "libnvonnxparsers11.txt")
endif()
endif()