1
-
2
1
# Copyright (c) Microsoft Corporation. All rights reserved.
3
2
# Licensed under the MIT License.
4
3
@@ -18,7 +17,7 @@ cmake_policy(SET CMP0104 OLD)
18
17
# Project
19
18
project (onnxruntime C CXX)
20
19
# Needed for Java
21
- set (CMAKE_C_STANDARD 99)
20
+ set (CMAKE_C_STANDARD 99)
22
21
23
22
include (CheckCXXCompilerFlag)
24
23
include (CheckLanguage)
@@ -108,17 +107,18 @@ option(onnxruntime_USE_ROCM "Build with AMD GPU support" OFF)
108
107
option (onnxruntime_DISABLE_CONTRIB_OPS "Disable contrib ops" OFF )
109
108
option (onnxruntime_DISABLE_ML_OPS "Disable traditional ML ops" OFF )
110
109
option (onnxruntime_DISABLE_SPARSE_TENSORS "Disable sparse tensors data types" OFF )
111
- cmake_dependent_option(onnxruntime_DISABLE_RTTI "Disable RTTI" ON "onnxruntime_MINIMAL_BUILD;NOT onnxruntime_ENABLE_PYTHON" OFF )
112
- # For now onnxruntime_DISABLE_EXCEPTIONS will only work with onnxruntime_MINIMAL_BUILD, more changes (ONNX, non-CPU EP, ...) are required to run this standalone
113
- option (onnxruntime_DISABLE_EXCEPTIONS "Disable exception handling. Requires onnxruntime_MINIMAL_BUILD currently." OFF )
114
110
option (onnxruntime_MINIMAL_BUILD "Exclude as much as possible from the build. Support ORT format models. No support for ONNX format models." OFF )
111
+ cmake_dependent_option(onnxruntime_DISABLE_RTTI "Disable RTTI" ON "NOT onnxruntime_ENABLE_PYTHON" OFF )
112
+ # For now onnxruntime_DISABLE_EXCEPTIONS will only work with onnxruntime_MINIMAL_BUILD, more changes (ONNX, non-CPU EP, ...) are required to run this standalone
113
+ cmake_dependent_option(onnxruntime_DISABLE_EXCEPTIONS "Disable exception handling. Requires onnxruntime_MINIMAL_BUILD currently." ON "onnxruntime_MINIMAL_BUILD;NOT onnxruntime_ENABLE_PYTHON" OFF )
114
+
115
115
option (onnxruntime_EXTENDED_MINIMAL_BUILD "onnxruntime_MINIMAL_BUILD with support for execution providers that compile kernels." OFF )
116
116
option (onnxruntime_MINIMAL_BUILD_CUSTOM_OPS "Add custom operator kernels support to a minimal build." OFF )
117
117
option (onnxruntime_REDUCED_OPS_BUILD "Reduced set of kernels are registered in build via modification of the kernel registration source files." OFF )
118
- option (onnxruntime_DISABLE_ORT_FORMAT_LOAD "Disable loading an ORT format model when onnxruntime_MINIMAL_BUILD=OFF (i.e. in a full build)." OFF )
119
118
option (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS "Don't allow models to load external data" OFF )
120
- cmake_dependent_option(onnxruntime_ENABLE_ORT_FORMAT_RUNTIME_GRAPH_OPTIMIZATION "Enable runtime graph optimization of ORT format models." ON
121
- "NOT onnxruntime_MINIMAL_BUILD OR onnxruntime_EXTENDED_MINIMAL_BUILD" OFF )
119
+ cmake_dependent_option(onnxruntime_ENABLE_ORT_FORMAT_RUNTIME_GRAPH_OPTIMIZATION
120
+ "Enable runtime graph optimization of ORT format models. Warning: Not yet ready for general use."
121
+ OFF "NOT onnxruntime_MINIMAL_BUILD OR onnxruntime_EXTENDED_MINIMAL_BUILD" OFF )
122
122
123
123
#A special option just for debugging and sanitize check. Please do not enable in option in retail builds.
124
124
#The option has no effect on Windows.
@@ -170,6 +170,13 @@ set(ONNX_CUSTOM_PROTOC_EXECUTABLE "" CACHE STRING "Specify custom protoc executa
170
170
# pre-build python path
171
171
option (onnxruntime_PREBUILT_PYTORCH_PATH "Path to pytorch installation dir" )
172
172
173
+ # external transformer src path
174
+ option (onnxruntime_EXTERNAL_TRANSFORMER_SRC_PATH "Path to external transformer src dir" )
175
+
176
+ if (onnxruntime_USE_CUDA)
177
+ set (onnxruntime_DISABLE_RTTI OFF )
178
+ endif ()
179
+
173
180
if (APPLE )
174
181
if (NOT CMAKE_OSX_ARCHITECTURES)
175
182
message ("Building ONNX Runtime for ${CMAKE_HOST_SYSTEM_PROCESSOR} " )
@@ -179,7 +186,7 @@ elseif (NOT WIN32 AND NOT APPLE)
179
186
endif ()
180
187
181
188
# Single output director for all binaries
182
- set (RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin CACHE PATH "Single output directory for all binaries." )
189
+ set (RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin CACHE PATH "Single output directory for all binaries." )
183
190
184
191
function (set_msvc_c_cpp_compiler_warning_level warning_level)
185
192
if (NOT "${warning_level} " MATCHES "^[0-4]$" )
@@ -282,8 +289,8 @@ endif()
282
289
if (onnxruntime_USE_OPENMP)
283
290
find_package (OpenMP)
284
291
if (OPENMP_FOUND)
285
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " )
286
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} " )
292
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} " )
293
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} " )
287
294
include_directories (${OpenMP_CXX_INCLUDE_DIR} )
288
295
else ()
289
296
message (WARNING "Flag --use_openmp is specified, but OpenMP is not found in current build environment. Setting it to OFF." )
@@ -329,10 +336,13 @@ if (onnxruntime_BUILD_WEBASSEMBLY)
329
336
endif ()
330
337
endif ()
331
338
339
+ if (onnxruntime_EXTERNAL_TRANSFORMER_SRC_PATH)
340
+ add_definitions (-DORT_TRAINING_EXTERNAL_GRAPH_TRANSFORMERS=1)
341
+ endif ()
342
+
332
343
# ORT build with as much excluded as possible. Supports ORT flatbuffers models only.
333
344
if (onnxruntime_MINIMAL_BUILD)
334
345
add_compile_definitions (ORT_MINIMAL_BUILD)
335
- add_compile_definitions (ENABLE_ORT_FORMAT_LOAD)
336
346
337
347
if (onnxruntime_EXTENDED_MINIMAL_BUILD)
338
348
# enable EPs that compile kernels at runtime
@@ -345,15 +355,10 @@ if (onnxruntime_MINIMAL_BUILD)
345
355
346
356
set (onnxruntime_REDUCED_OPS_BUILD ON )
347
357
348
- if (NOT onnxruntime_ENABLE_PYTHON)
349
- # Python bindings use typeid so can't automatically disable RTTI in that case
350
- set (onnxruntime_DISABLE_RTTI ON )
351
- endif ()
352
-
353
358
if (MSVC )
354
359
# turn on LTO (which adds some compiler flags and turns on LTCG) unless it's a Debug build to minimize binary size
355
360
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
356
- set (onnxruntime_ENABLE_LTO ON )
361
+ set (onnxruntime_ENABLE_LTO ON )
357
362
endif ()
358
363
359
364
# undocumented internal flag to allow analysis of a minimal build binary size
@@ -374,11 +379,6 @@ if (onnxruntime_MINIMAL_BUILD)
374
379
string (APPEND CMAKE_C_FLAGS " -g" )
375
380
endif ()
376
381
endif ()
377
- else ()
378
- # support ORT format model loading unless onnxruntime_DISABLE_ORT_FORMAT_LOAD is set
379
- if (NOT onnxruntime_DISABLE_ORT_FORMAT_LOAD)
380
- add_compile_definitions (ENABLE_ORT_FORMAT_LOAD)
381
- endif ()
382
382
endif ()
383
383
384
384
if (onnxruntime_ENABLE_ORT_FORMAT_RUNTIME_GRAPH_OPTIMIZATION)
@@ -392,7 +392,7 @@ if (onnxruntime_ENABLE_LTO)
392
392
message (WARNING "IPO is not supported by this compiler" )
393
393
set (onnxruntime_ENABLE_LTO OFF )
394
394
else ()
395
- set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
395
+ set (CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
396
396
endif ()
397
397
endif ()
398
398
@@ -405,7 +405,7 @@ if (onnxruntime_DISABLE_EXTERNAL_INITIALIZERS)
405
405
endif ()
406
406
407
407
if (onnxruntime_DISABLE_RTTI)
408
- add_compile_definitions (ORT_NO_RTTI GOOGLE_PROTOBUF_NO_RTTI )
408
+ add_compile_definitions (ORT_NO_RTTI)
409
409
if (MSVC )
410
410
# Disable RTTI and turn usage of dynamic_cast and typeid into errors
411
411
add_compile_options ("$<$<COMPILE_LANGUAGE:CXX>:/GR->" "$<$<COMPILE_LANGUAGE:CXX>:/we4541>" )
@@ -427,6 +427,10 @@ if (onnxruntime_DISABLE_EXCEPTIONS)
427
427
message (FATAL_ERROR "onnxruntime_MINIMAL_BUILD required for onnxruntime_DISABLE_EXCEPTIONS" )
428
428
endif ()
429
429
430
+ if (onnxruntime_ENABLE_PYTHON)
431
+ # pybind11 highly depends on C++ exceptions.
432
+ message (FATAL_ERROR "onnxruntime_ENABLE_PYTHON must be disabled for onnxruntime_DISABLE_EXCEPTIONS" )
433
+ endif ()
430
434
add_compile_definitions ("ORT_NO_EXCEPTIONS" )
431
435
add_compile_definitions ("MLAS_NO_EXCEPTION" )
432
436
add_compile_definitions ("ONNX_NO_EXCEPTIONS" )
@@ -552,30 +556,30 @@ if (MSVC)
552
556
endif ()
553
557
554
558
if (onnxruntime_ENABLE_LTO AND NOT onnxruntime_USE_CUDA)
555
- SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Gw /GL" )
556
- SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Gw /GL" )
557
- SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Gw /GL" )
559
+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Gw /GL" )
560
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Gw /GL" )
561
+ set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Gw /GL" )
558
562
endif ()
559
563
560
564
# The WinML build tool chain builds ARM/ARM64, and the internal tool chain does not have folders for spectre mitigation libs.
561
565
# WinML performs spectre mitigation differently.
562
566
if (NOT DEFINED onnxruntime_DISABLE_QSPECTRE_CHECK)
563
567
check_cxx_compiler_flag(-Qspectre HAS_QSPECTRE)
564
568
if (HAS_QSPECTRE)
565
- SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre" )
566
- SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre" )
569
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Qspectre" )
570
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre" )
567
571
endif ()
568
572
endif ()
569
- SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE" )
573
+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DYNAMICBASE" )
570
574
check_cxx_compiler_flag(-guard:cf HAS_GUARD_CF)
571
575
if (HAS_GUARD_CF)
572
- SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /guard:cf" )
573
- SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /guard:cf" )
574
- SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /guard:cf" )
575
- SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /guard:cf" )
576
- SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /guard:cf" )
577
- SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /guard:cf" )
578
- SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf" )
576
+ set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /guard:cf" )
577
+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /guard:cf" )
578
+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /guard:cf" )
579
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /guard:cf" )
580
+ set (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /guard:cf" )
581
+ set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /guard:cf" )
582
+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf" )
579
583
endif ()
580
584
else ()
581
585
if (NOT APPLE )
@@ -630,7 +634,7 @@ endif()
630
634
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
631
635
#For Mac compliance
632
636
message ("Adding flags for Mac builds" )
633
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong" )
637
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong" )
634
638
endif ()
635
639
636
640
#Dependencies begin
@@ -736,7 +740,7 @@ else()
736
740
set (protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support" FORCE)
737
741
endif ()
738
742
if (onnxruntime_DISABLE_RTTI)
739
- set (protobuf_DISABLE_RTTI OFF CACHE BOOL "Remove runtime type information in the binaries" FORCE)
743
+ set (protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE)
740
744
endif ()
741
745
add_subdirectory (${PROJECT_SOURCE_DIR} /external/protobuf/cmake EXCLUDE_FROM_ALL )
742
746
@@ -931,11 +935,15 @@ if (WIN32)
931
935
list (APPEND ORT_WARNING_FLAGS "/wd4251" )
932
936
# issued by thrust nonstandard extension used: nameless struct/union
933
937
list (APPEND ORT_WARNING_FLAGS "/wd4201" )
938
+ # warning C4800: Implicit conversion from 'X' to bool. Possible information loss
939
+ list (APPEND ORT_WARNING_FLAGS "/w34800" )
934
940
if (onnxruntime_USE_OPENMP)
935
941
list (APPEND ORT_WARNING_FLAGS "/wd6993" ) # Code analysis ignores OpenMP constructs
936
942
endif ()
937
943
# operator 'operator-name': deprecated between enumerations of different types
938
944
list (APPEND ORT_WARNING_FLAGS "/wd5054" )
945
+ # Enable warning: data member 'member' will be initialized after data member 'member2' / base class 'base_class'
946
+ list (APPEND ORT_WARNING_FLAGS "/w15038" )
939
947
# Treat warning as error if onnxruntime_DEV_MODE is ON
940
948
# For cross-compiled ARM64 binaries, there are too many warnings to fix, hence ignore warnings for now
941
949
if (onnxruntime_DEV_MODE AND NOT CMAKE_CROSSCOMPILING )
@@ -1503,6 +1511,11 @@ if (onnxruntime_USE_OPENVINO)
1503
1511
add_definitions (-DDEVICE_NAME="${onnxruntime_USE_OPENVINO_DEVICE} " )
1504
1512
endif ()
1505
1513
1514
+ if (onnxruntime_USE_OPENVINO_AUTO)
1515
+ add_definitions (-DOPENVINO_CONFIG_AUTO=1)
1516
+ add_definitions (-DDEVICE_NAME="${onnxruntime_USE_OPENVINO_DEVICE} " )
1517
+ endif ()
1518
+
1506
1519
endif ()
1507
1520
1508
1521
if (onnxruntime_USE_VITISAI)
0 commit comments