onnxruntime

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

4
file(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

10
if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
11
  file(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
  )
15
  list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_torch_srcs})
16
  if (onnxruntime_ENABLE_TRITON)
17
    file(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
    )
21
    list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_triton_srcs})
22
  endif()
23
elseif(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.
27
  file(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
  )
35
  list(APPEND onnxruntime_framework_srcs ${onnxruntime_training_framework_triton_srcs})
36
endif()
37

38
if (onnxruntime_MINIMAL_BUILD)
39
  set(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.
45
  if (NOT onnxruntime_MINIMAL_BUILD_CUSTOM_OPS)
46
    list(APPEND onnxruntime_framework_src_exclude
47
      "${ONNXRUNTIME_INCLUDE_DIR}/core/framework/customregistry.h"
48
      "${ONNXRUNTIME_ROOT}/core/framework/customregistry.cc"
49
    )
50
  endif()
51

52
  list(REMOVE_ITEM onnxruntime_framework_srcs ${onnxruntime_framework_src_exclude})
53
endif()
54

55
source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_framework_srcs})
56

57
onnxruntime_add_static_library(onnxruntime_framework ${onnxruntime_framework_srcs})
58

59
if (MSVC)
60
  set(ORT_FRAMEWORK_NATVIS_FILE "onnxruntime_framework.natvis")
61
  target_sources(
62
      onnxruntime_framework
63
      INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${ORT_FRAMEWORK_NATVIS_FILE}>)
64
endif()
65

66
if(onnxruntime_ENABLE_INSTRUMENT)
67
  target_compile_definitions(onnxruntime_framework PRIVATE ONNXRUNTIME_ENABLE_INSTRUMENT)
68
endif()
69
if(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
72
target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
73
else()
74
target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
75
endif()
76
# Needed for the provider interface, as it includes training headers when training is enabled
77
if (onnxruntime_ENABLE_TRAINING_OPS)
78
  target_include_directories(onnxruntime_framework PRIVATE ${ORTTRAINING_ROOT})
79
  if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP OR onnxruntime_ENABLE_TRITON)
80
    onnxruntime_add_include_to_target(onnxruntime_framework Python::Module)
81
    target_include_directories(onnxruntime_framework PRIVATE ${dlpack_SOURCE_DIR}/include)
82
  endif()
83
endif()
84
if (onnxruntime_USE_MPI)
85
  target_include_directories(onnxruntime_framework PUBLIC ${MPI_CXX_INCLUDE_DIRS})
86
endif()
87

88
if (onnxruntime_ENABLE_ATEN)
89
  # DLPack is a header-only dependency
90
  set(DLPACK_INCLUDE_DIR ${dlpack_SOURCE_DIR}/include)
91
  target_include_directories(onnxruntime_framework PRIVATE ${DLPACK_INCLUDE_DIR})
92
endif()
93
onnxruntime_add_include_to_target(onnxruntime_framework onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} flatbuffers::flatbuffers safeint_interface Boost::mp11 nlohmann_json::nlohmann_json)
94

95
if (onnxruntime_USE_MIMALLOC)
96
    target_link_libraries(onnxruntime_framework mimalloc-static)
97
endif()
98

99
if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
100
  target_link_libraries(onnxruntime_framework ${ABSEIL_LIBS})
101
endif()
102

103
set_target_properties(onnxruntime_framework PROPERTIES FOLDER "ONNXRuntime")
104
# need onnx to build to create headers that this project includes
105
add_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
111
if (UNIX AND NOT APPLE AND NOT onnxruntime_MINIMAL_BUILD AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
112
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
113
endif()
114

115
if (onnxruntime_DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
116
  find_package (SQLite3 REQUIRED)
117
  include_directories(${SQLite3_INCLUDE_DIR})
118
  target_link_libraries (onnxruntime_framework ${SQLite3_LIBRARY})
119
  target_compile_definitions(onnxruntime_framework PRIVATE DEBUG_NODE_INPUTS_OUTPUTS_ENABLE_DUMP_TO_SQLDB)
120
endif()
121

122
if (WIN32)
123
  target_compile_definitions(onnxruntime_framework PRIVATE _SCL_SECURE_NO_WARNINGS)
124
endif()
125

126
if (onnxruntime_BUILD_SHARED_LIB)
127
  install(FILES ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework/provider_options.h  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/)
128
else()
129
  install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core)
130
  install(TARGETS onnxruntime_framework
131
            ARCHIVE   DESTINATION ${CMAKE_INSTALL_LIBDIR}
132
            LIBRARY   DESTINATION ${CMAKE_INSTALL_LIBDIR}
133
            RUNTIME   DESTINATION ${CMAKE_INSTALL_BINDIR}
134
            FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR})
135
endif()
136

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

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

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

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