onnxruntime
135 строк · 6.5 Кб
1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4file(GLOB_RECURSE onnxruntime_framework_srcs CONFIGURE_DEPENDS
5"${ONNXRUNTIME_INCLUDE_DIR}/core/framework/*.h"
6"${ONNXRUNTIME_ROOT}/core/framework/*.h"
7"${ONNXRUNTIME_ROOT}/core/framework/*.cc"
8)
9
10if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
11file(GLOB_RECURSE onnxruntime_training_framework_torch_srcs CONFIGURE_DEPENDS
12"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/*.h"
13"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/*.cc"
14)
15list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_torch_srcs})
16if (onnxruntime_ENABLE_TRITON)
17file(GLOB_RECURSE onnxruntime_training_framework_triton_srcs CONFIGURE_DEPENDS
18"${ORTTRAINING_SOURCE_DIR}/core/framework/triton/*.h"
19"${ORTTRAINING_SOURCE_DIR}/core/framework/triton/*.cc"
20)
21list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_triton_srcs})
22endif()
23elseif(onnxruntime_ENABLE_TRITON)
24# Triton executor shares some code from torch_interop, such as python and dlpack related code files.
25# When torch_interop is enabled, all these dependencies are already included.
26# But if not, we need to include them explicitly.
27file(GLOB_RECURSE onnxruntime_training_framework_triton_srcs CONFIGURE_DEPENDS
28"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/dlpack_python.h"
29"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/dlpack_python.cc"
30"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/gil.h"
31"${ORTTRAINING_SOURCE_DIR}/core/framework/torch/python_common.h"
32"${ORTTRAINING_SOURCE_DIR}/core/framework/triton/*.h"
33"${ORTTRAINING_SOURCE_DIR}/core/framework/triton/*.cc"
34)
35list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_triton_srcs})
36endif()
37
38if (onnxruntime_MINIMAL_BUILD)
39set(onnxruntime_framework_src_exclude
40"${ONNXRUNTIME_ROOT}/core/framework/fallback_cpu_capability.h"
41"${ONNXRUNTIME_ROOT}/core/framework/fallback_cpu_capability.cc"
42)
43
44# custom ops support must be explicitly enabled in a minimal build. exclude if not.
45if (NOT onnxruntime_MINIMAL_BUILD_CUSTOM_OPS)
46list(APPEND onnxruntime_framework_src_exclude
47"${ONNXRUNTIME_INCLUDE_DIR}/core/framework/customregistry.h"
48"${ONNXRUNTIME_ROOT}/core/framework/customregistry.cc"
49)
50endif()
51
52list(REMOVE_ITEM onnxruntime_framework_srcs ${onnxruntime_framework_src_exclude})
53endif()
54
55source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_framework_srcs})
56
57onnxruntime_add_static_library(onnxruntime_framework ${onnxruntime_framework_srcs})
58
59if (MSVC)
60set(ORT_FRAMEWORK_NATVIS_FILE "onnxruntime_framework.natvis")
61target_sources(
62onnxruntime_framework
63INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${ORT_FRAMEWORK_NATVIS_FILE}>)
64endif()
65
66if(onnxruntime_ENABLE_INSTRUMENT)
67target_compile_definitions(onnxruntime_framework PRIVATE ONNXRUNTIME_ENABLE_INSTRUMENT)
68endif()
69if(onnxruntime_USE_TENSORRT OR onnxruntime_USE_NCCL)
70# TODO: for now, core framework depends on CUDA. It should be moved to TensorRT EP
71# TODO: provider_bridge_ort.cc should not include nccl.h
72target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
73else()
74target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
75endif()
76# Needed for the provider interface, as it includes training headers when training is enabled
77if (onnxruntime_ENABLE_TRAINING_OPS)
78target_include_directories(onnxruntime_framework PRIVATE ${ORTTRAINING_ROOT})
79if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP OR onnxruntime_ENABLE_TRITON)
80onnxruntime_add_include_to_target(onnxruntime_framework Python::Module)
81target_include_directories(onnxruntime_framework PRIVATE ${dlpack_SOURCE_DIR}/include)
82endif()
83endif()
84if (onnxruntime_USE_MPI)
85target_include_directories(onnxruntime_framework PUBLIC ${MPI_CXX_INCLUDE_DIRS})
86endif()
87
88if (onnxruntime_ENABLE_ATEN)
89# DLPack is a header-only dependency
90set(DLPACK_INCLUDE_DIR ${dlpack_SOURCE_DIR}/include)
91target_include_directories(onnxruntime_framework PRIVATE ${DLPACK_INCLUDE_DIR})
92endif()
93onnxruntime_add_include_to_target(onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers safeint_interface Boost::mp11 nlohmann_json::nlohmann_json)
94
95if (onnxruntime_USE_MIMALLOC)
96target_link_libraries(onnxruntime_framework mimalloc-static)
97endif()
98
99if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
100target_link_libraries(onnxruntime_framework ${ABSEIL_LIBS})
101endif()
102
103set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
104# need onnx to build to create headers that this project includes
105add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES})
106
107# In order to find the shared provider libraries we need to add the origin to the rpath for all executables we build
108# For the shared onnxruntime library, this is set in onnxruntime.cmake through CMAKE_SHARED_LINKER_FLAGS
109# But our test files don't use the shared library so this must be set for them.
110# For Win32 it generates an absolute path for shared providers based on the location of the executable/onnxruntime.dll
111if (UNIX AND NOT APPLE AND NOT onnxruntime_MINIMAL_BUILD AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
112set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
113endif()
114
115if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
116find_package (SQLite3 REQUIRED)
117include_directories(${SQLite3_INCLUDE_DIR})
118target_link_libraries (onnxruntime_framework ${SQLite3_LIBRARY})
119target_compile_definitions(onnxruntime_framework PRIVATE DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
120endif()
121
122if (WIN32)
123target_compile_definitions(onnxruntime_framework PRIVATE _SCL_SECURE_NO_WARNINGS)
124endif()
125
126if (onnxruntime_BUILD_SHARED_LIB)
127install(FILES ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework/provider_options.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/)
128else()
129install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
130install(TARGETS onnxruntime_framework
131ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
132LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
133RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
134FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
135endif()
136