onnxruntime

Форк
0
/
onnxruntime_graph.cmake 
165 строк · 6.3 Кб
1
# Copyright (c) Microsoft Corporation. All rights reserved.
2
# Licensed under the MIT License.
3

4
file(GLOB_RECURSE onnxruntime_graph_src CONFIGURE_DEPENDS
5
  "${ONNXRUNTIME_INCLUDE_DIR}/core/graph/*.h"
6
  "${ONNXRUNTIME_ROOT}/core/graph/*.h"
7
  "${ONNXRUNTIME_ROOT}/core/graph/*.cc"
8
  )
9

10
# start with empty training srcs list
11
set(orttraining_graph_src)
12

13
if (onnxruntime_ENABLE_TRAINING_OPS AND NOT onnxruntime_ENABLE_TRAINING)
14
  set(orttraining_graph_src
15
      "${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
16
      "${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
17
      )
18
endif()
19

20
if (onnxruntime_ENABLE_TRAINING)
21
  file(GLOB_RECURSE orttraining_graph_src CONFIGURE_DEPENDS
22
      "${ORTTRAINING_SOURCE_DIR}/core/graph/*.h"
23
      "${ORTTRAINING_SOURCE_DIR}/core/graph/*.cc"
24
      )
25
endif()
26

27
# create empty lists for any excludes
28
set(onnxruntime_graph_src_exclude_patterns)
29
set(orttraining_graph_src_exclude_patterns)
30

31
if (onnxruntime_MINIMAL_BUILD)
32
  # remove schema registration support
33
  list(APPEND onnxruntime_graph_src_exclude_patterns
34
    "${ONNXRUNTIME_INCLUDE_DIR}/core/graph/schema_registry.h"
35
    "${ONNXRUNTIME_ROOT}/core/graph/schema_registry.cc"
36
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.h"
37
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*defs.cc"
38
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_deprecated_operators.cc"
39
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.h"
40
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/onnx_function_util.cc"
41
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.h"
42
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/shape_inference_functions.cc"
43
    "${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.h"
44
    "${ONNXRUNTIME_ROOT}/core/graph/dml_ops/dml_defs.cc"
45
    "${ONNXRUNTIME_ROOT}/core/graph/function_template.h"
46
    "${ONNXRUNTIME_ROOT}/core/graph/function_utils.h"
47
    "${ONNXRUNTIME_ROOT}/core/graph/function_utils.cc"
48
  )
49

50
  list(APPEND orttraining_graph_src_exclude_patterns
51
    "${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.h"
52
    "${ORTTRAINING_SOURCE_DIR}/core/graph/training_op_defs.cc"
53
  )
54

55
  # no Function support initially
56
  list(APPEND onnxruntime_graph_src_exclude_patterns
57
    "${ONNXRUNTIME_ROOT}/core/graph/function*"
58
  )
59

60
  # remove graph proto serializer
61
  list(APPEND onnxruntime_graph_src_exclude_patterns
62
    "${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.cc"
63
    "${ONNXRUNTIME_ROOT}/core/graph/graph_proto_serializer.h"
64
  )
65

66
  # no optimizer support in base minimal build
67
  # some optimizer support in extended minimal build
68
  if (NOT onnxruntime_EXTENDED_MINIMAL_BUILD)
69
    list(APPEND onnxruntime_graph_src_exclude_patterns
70
      "${ONNXRUNTIME_ROOT}/core/graph/graph_utils.*"
71
    )
72
  endif()
73
endif()
74

75
if (onnxruntime_DISABLE_CONTRIB_OPS)
76
  list(APPEND onnxruntime_graph_src_exclude_patterns
77
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.h"
78
    "${ONNXRUNTIME_ROOT}/core/graph/contrib_ops/*.cc"
79
    )
80
endif()
81

82
if(NOT onnxruntime_USE_DML)
83
  list(APPEND onnxruntime_graph_src_exclude_patterns
84
    "${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.h"
85
    "${ONNXRUNTIME_ROOT}/core/graph/dml_ops/*.cc"
86
    )
87
endif()
88

89
file(GLOB onnxruntime_graph_src_exclude ${onnxruntime_graph_src_exclude_patterns})
90
list(REMOVE_ITEM onnxruntime_graph_src ${onnxruntime_graph_src_exclude})
91

92
if (onnxruntime_ENABLE_TRAINING_OPS)
93
  file(GLOB orttraining_graph_src_exclude ${orttraining_graph_src_exclude_patterns})
94
  list(REMOVE_ITEM orttraining_graph_src ${orttraining_graph_src_exclude})
95
endif()
96

97
onnxruntime_add_static_library(onnxruntime_graph ${onnxruntime_graph_src} ${orttraining_graph_src})
98
add_dependencies(onnxruntime_graph onnx_proto flatbuffers::flatbuffers)
99
onnxruntime_add_include_to_target(onnxruntime_graph onnxruntime_common ${WIL_TARGET} onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers safeint_interface Boost::mp11)
100

101
if (MSVC)
102
  set(ONNX_PROTOBUF_NATVIS_FILE "onnx_protobuf.natvis")
103
  target_sources(
104
      onnxruntime_graph
105
      INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/external/${ONNX_PROTOBUF_NATVIS_FILE}>
106
  )
107
endif()
108

109
if(NOT MSVC)
110
  target_compile_options(onnxruntime_graph PRIVATE "-Wno-parentheses" "-Wno-deprecated-declarations")
111
endif()
112
if (onnxruntime_ENABLE_TRAINING)
113
  #TODO: the graph library should focus on ONNX IR, it shouldn't depend on math libraries like MKLML/OpenBlas
114
  target_include_directories(onnxruntime_graph PRIVATE ${MKLML_INCLUDE_DIR})
115
  target_link_libraries(onnxruntime_graph PRIVATE nlohmann_json::nlohmann_json)
116
endif()
117

118
target_include_directories(onnxruntime_graph PRIVATE ${ONNXRUNTIME_ROOT})
119

120
if (onnxruntime_ENABLE_TRAINING_OPS)
121
    target_include_directories(onnxruntime_graph PRIVATE ${ORTTRAINING_ROOT})
122

123
    if (onnxruntime_USE_NCCL)
124
        target_include_directories(onnxruntime_graph PRIVATE ${NCCL_INCLUDE_DIRS})
125
    endif()
126
endif()
127

128
set_target_properties(onnxruntime_graph PROPERTIES FOLDER "ONNXRuntime")
129
set_target_properties(onnxruntime_graph PROPERTIES LINKER_LANGUAGE CXX)
130
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_graph_src})
131
if (onnxruntime_ENABLE_TRAINING_OPS)
132
    source_group(TREE ${ORTTRAINING_ROOT} FILES ${orttraining_graph_src})
133
endif()
134

135
if (onnxruntime_BUILD_MS_EXPERIMENTAL_OPS)
136
  target_compile_definitions(onnxruntime_graph PRIVATE BUILD_MS_EXPERIMENTAL_OPS=1)
137
endif()
138

139
if (WIN32)
140
  set(onnxruntime_graph_static_library_flags
141
      -IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
142
  )
143

144
  set_target_properties(onnxruntime_graph PROPERTIES
145
      STATIC_LIBRARY_FLAGS "${onnxruntime_graph_static_library_flags}")
146

147
  if (NOT onnxruntime_DISABLE_EXCEPTIONS)
148
    target_compile_options(onnxruntime_graph PRIVATE
149
        /EHsc   # exception handling - C++ may throw, extern "C" will not
150
    )
151
  endif()
152
endif()
153

154
if (onnxruntime_ENABLE_ATEN)
155
  target_compile_definitions(onnxruntime_graph PRIVATE ENABLE_ATEN)
156
endif()
157

158
if (NOT onnxruntime_BUILD_SHARED_LIB)
159
  install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
160
  install(TARGETS onnxruntime_graph
161
            ARCHIVE   DESTINATION ${CMAKE_INSTALL_LIBDIR}
162
            LIBRARY   DESTINATION ${CMAKE_INSTALL_LIBDIR}
163
            RUNTIME   DESTINATION ${CMAKE_INSTALL_BINDIR}
164
            FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
165
endif()
166

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.