onnxruntime
1040 строк · 50.2 Кб
1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4include(pybind11)
5
6# ---[ Python + Numpy
7set(onnxruntime_pybind_srcs_pattern
8"${ONNXRUNTIME_ROOT}/python/*.cc"
9"${ONNXRUNTIME_ROOT}/python/*.h"
10)
11
12if (onnxruntime_ENABLE_TRAINING)
13list(APPEND onnxruntime_pybind_srcs_pattern
14"${ORTTRAINING_ROOT}/orttraining/python/*.cc"
15"${ORTTRAINING_ROOT}/orttraining/python/*.h"
16)
17endif()
18
19file(GLOB onnxruntime_pybind_srcs CONFIGURE_DEPENDS
20${onnxruntime_pybind_srcs_pattern}
21)
22
23if(onnxruntime_ENABLE_TRAINING)
24list(REMOVE_ITEM onnxruntime_pybind_srcs ${ONNXRUNTIME_ROOT}/python/onnxruntime_pybind_module.cc)
25endif()
26
27# Add Pytorch as a library.
28if (onnxruntime_ENABLE_LAZY_TENSOR)
29# Lazy Tensor requires Pytorch as a library.
30list(APPEND CMAKE_PREFIX_PATH ${onnxruntime_PREBUILT_PYTORCH_PATH})
31# The following line may change ${CUDA_NVCC_FLAGS} and ${CMAKE_CUDA_FLAGS},
32# if Pytorch is built from source.
33# For example, pytorch/cmake/public/cuda.cmake and
34# pytorch/torch/share/cmake/Caffe2/public/cuda.cmake both defines
35# ONNX_NAMESPACE for both CUDA_NVCC_FLAGS and CMAKE_CUDA_FLAGS.
36# Later, this ONNX_NAMESPACE may conflicts with ONNX_NAMESPACE set by ORT.
37find_package(Torch REQUIRED)
38# Let's remove ONNX_NAMESPACE from Torch.
39list(FILTER CUDA_NVCC_FLAGS EXCLUDE REGEX "-DONNX_NAMESPACE=.+")
40string(REGEX REPLACE "-DONNX_NAMESPACE=.+ " " " CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS}")
41endif()
42
43# Support ORT as a backend in Pytorch's LazyTensor.
44if (onnxruntime_ENABLE_LAZY_TENSOR)
45file(GLOB onnxruntime_lazy_tensor_extension_srcs CONFIGURE_DEPENDS
46"${ORTTRAINING_ROOT}/orttraining/lazy_tensor/*.cc")
47file(GLOB onnxruntime_lazy_tensor_extension_headers CONFIGURE_DEPENDS
48"${ORTTRAINING_ROOT}/orttraining/lazy_tensor/*.h")
49
50if(NOT MSVC)
51set_source_files_properties(${onnxruntime_lazy_tensor_extension_srcs} PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
52set_source_files_properties(${onnxruntime_lazy_tensor_extension_headers} PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
53endif()
54
55list(APPEND onnxruntime_pybind_srcs
56${onnxruntime_lazy_tensor_extension_srcs})
57endif()
58
59# onnxruntime_ENABLE_LAZY_TENSOR and onnxruntime_ENABLE_EAGER_MODE
60# need DLPack code to pass tensors cross ORT and Pytorch boundary.
61# TODO: consider making DLPack code a standalone library.
62if (onnxruntime_ENABLE_LAZY_TENSOR)
63# If DLPack code is not built, add it to ORT's pybind target.
64if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP)
65list(APPEND onnxruntime_pybind_srcs
66"${ORTTRAINING_ROOT}/orttraining/core/framework/torch/dlpack_python.cc")
67endif()
68endif()
69
70onnxruntime_add_shared_library_module(onnxruntime_pybind11_state ${onnxruntime_pybind_srcs})
71
72if(MSVC)
73target_compile_options(onnxruntime_pybind11_state PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:--compiler-options /utf-8>" "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:/utf-8>")
74if(onnxruntime_ENABLE_TRAINING)
75target_compile_options(onnxruntime_pybind11_state PRIVATE "/bigobj")
76endif()
77endif()
78if(HAS_CAST_FUNCTION_TYPE)
79target_compile_options(onnxruntime_pybind11_state PRIVATE "-Wno-cast-function-type")
80endif()
81
82# We export symbols using linker and the compiler does not know anything about it
83# There is a problem with classes that have pybind types as members.
84# See https://pybind11.readthedocs.io/en/stable/faq.html#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclass-member-wattributes
85if (NOT MSVC)
86target_compile_options(onnxruntime_pybind11_state PRIVATE "-fvisibility=hidden")
87endif()
88
89if(onnxruntime_PYBIND_EXPORT_OPSCHEMA)
90target_compile_definitions(onnxruntime_pybind11_state PRIVATE onnxruntime_PYBIND_EXPORT_OPSCHEMA)
91endif()
92
93if (MSVC AND NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
94#TODO: fix the warnings
95target_compile_options(onnxruntime_pybind11_state PRIVATE "/wd4244")
96endif()
97
98onnxruntime_add_include_to_target(onnxruntime_pybind11_state Python::Module Python::NumPy)
99target_include_directories(onnxruntime_pybind11_state PRIVATE ${ONNXRUNTIME_ROOT} ${pybind11_INCLUDE_DIRS})
100if(onnxruntime_USE_CUDA)
101target_include_directories(onnxruntime_pybind11_state PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES} ${CUDNN_INCLUDE_DIR})
102endif()
103if(onnxruntime_USE_CANN)
104target_include_directories(onnxruntime_pybind11_state PRIVATE ${onnxruntime_CANN_HOME}/include)
105endif()
106if(onnxruntime_USE_ROCM)
107target_compile_options(onnxruntime_pybind11_state PUBLIC -D__HIP_PLATFORM_AMD__=1 -D__HIP_PLATFORM_HCC__=1)
108target_include_directories(onnxruntime_pybind11_state PRIVATE ${onnxruntime_ROCM_HOME}/hipfft/include ${onnxruntime_ROCM_HOME}/include ${onnxruntime_ROCM_HOME}/hiprand/include ${onnxruntime_ROCM_HOME}/rocrand/include ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/orttraining)
109endif()
110if (onnxruntime_USE_NCCL)
111target_include_directories(onnxruntime_pybind11_state PRIVATE ${NCCL_INCLUDE_DIRS})
112endif()
113
114if(APPLE)
115set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker -exported_symbols_list -Xlinker ${ONNXRUNTIME_ROOT}/python/exported_symbols.lst")
116elseif(UNIX)
117if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
118set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/python/version_script_expose_onnx_protobuf.lds -Xlinker --gc-sections")
119else()
120if (NOT CMAKE_SYSTEM_NAME MATCHES "AIX")
121set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/python/version_script.lds -Xlinker --gc-sections")
122endif()
123endif()
124else()
125set(ONNXRUNTIME_SO_LINK_FLAG "-DEF:${ONNXRUNTIME_ROOT}/python/pybind.def")
126endif()
127
128if (onnxruntime_ENABLE_ATEN)
129target_compile_definitions(onnxruntime_pybind11_state PRIVATE ENABLE_ATEN)
130target_include_directories(onnxruntime_pybind11_state PRIVATE ${dlpack_SOURCE_DIR}/include)
131endif()
132
133if (onnxruntime_ENABLE_TRAINING)
134target_include_directories(onnxruntime_pybind11_state PRIVATE ${ORTTRAINING_ROOT})
135target_link_libraries(onnxruntime_pybind11_state PRIVATE onnxruntime_training)
136endif()
137
138# Eager mode and LazyTensor are both Pytorch's backends, so their
139# dependencies are set together below.
140if (onnxruntime_ENABLE_LAZY_TENSOR)
141# Set library dependencies shared by aforementioned backends.
142
143# todo: this is because the prebuild pytorch may use a different version of protobuf headers.
144# force the build to find the protobuf headers ort using.
145target_include_directories(onnxruntime_pybind11_state PRIVATE
146"${REPO_ROOT}/cmake/external/protobuf/src"
147${TORCH_INCLUDE_DIRS})
148
149# For eager mode, torch build has a mkl dependency from torch's cmake config,
150# Linking to torch libraries to avoid this unnecessary mkl dependency.
151target_include_directories(onnxruntime_pybind11_state PRIVATE "${TORCH_INSTALL_PREFIX}/include" "${TORCH_INSTALL_PREFIX}/include/torch/csrc/api/include")
152find_library(LIBTORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
153find_library(LIBTORCH_CPU_LIBRARY torch_cpu PATHS "${TORCH_INSTALL_PREFIX}/lib")
154find_library(LIBC10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib")
155# Explicitly link torch_python to workaround https://github.com/pytorch/pytorch/issues/38122#issuecomment-694203281
156find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
157target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_LIBRARY} ${LIBTORCH_CPU_LIBRARY} ${LIBC10_LIBRARY} ${TORCH_PYTHON_LIBRARY})
158if (onnxruntime_USE_CUDA)
159find_library(LIBTORCH_CUDA_LIBRARY torch_cuda PATHS "${TORCH_INSTALL_PREFIX}/lib")
160find_library(LIBC10_CUDA_LIBRARY c10_cuda PATHS "${TORCH_INSTALL_PREFIX}/lib")
161target_link_libraries(onnxruntime_pybind11_state PRIVATE ${LIBTORCH_CUDA_LIBRARY} ${LIBC10_CUDA_LIBRARY})
162endif()
163
164
165if (MSVC)
166target_compile_options(onnxruntime_pybind11_state PRIVATE "/wd4100" "/wd4324" "/wd4458" "/wd4127" "/wd4193" "/wd4624" "/wd4702")
167target_compile_options(onnxruntime_pybind11_state PRIVATE "/bigobj" "/wd4275" "/wd4244" "/wd4267" "/wd4067")
168endif()
169endif()
170
171target_link_libraries(onnxruntime_pybind11_state PRIVATE
172onnxruntime_session
173${onnxruntime_libs}
174${PROVIDERS_TVM}
175${PROVIDERS_NNAPI}
176${PROVIDERS_XNNPACK}
177${PROVIDERS_COREML}
178${PROVIDERS_RKNPU}
179${PROVIDERS_DML}
180${PROVIDERS_ACL}
181${PROVIDERS_ARMNN}
182${PROVIDERS_XNNPACK}
183${PROVIDERS_AZURE}
184${PROVIDERS_QNN}
185onnxruntime_optimizer
186onnxruntime_providers
187onnxruntime_util
188${onnxruntime_tvm_libs}
189onnxruntime_framework
190onnxruntime_util
191onnxruntime_graph
192${ONNXRUNTIME_MLAS_LIBS}
193onnxruntime_common
194onnxruntime_flatbuffers
195${pybind11_lib}
196)
197
198set(onnxruntime_pybind11_state_dependencies
199${onnxruntime_EXTERNAL_DEPENDENCIES}
200${pybind11_dep}
201)
202set_property(TARGET onnxruntime_pybind11_state APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_SO_LINK_FLAG} ${onnxruntime_DELAYLOAD_FLAGS})
203add_dependencies(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_dependencies})
204
205if (MSVC)
206set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "${ONNXRUNTIME_SO_LINK_FLAG}")
207# if MSVC, pybind11 undefines _DEBUG in pybind11/detail/common.h, which causes the pragma in pyconfig.h
208# from the python installation to require the release version of the lib
209# e.g. from a python 3.10 install:
210# if defined(_DEBUG)
211# pragma comment(lib,"python310_d.lib")
212# elif defined(Py_LIMITED_API)
213# pragma comment(lib,"python3.lib")
214# else
215# pragma comment(lib,"python310.lib")
216# endif /* _DEBUG */
217#
218# See https://github.com/pybind/pybind11/issues/3403 for more background info.
219#
220# Explicitly use the release version of the python library to make the project file consistent with this.
221target_link_libraries(onnxruntime_pybind11_state PRIVATE ${Python_LIBRARY_RELEASE})
222elseif (APPLE)
223set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "${ONNXRUNTIME_SO_LINK_FLAG} -Xlinker -undefined -Xlinker dynamic_lookup")
224set_target_properties(onnxruntime_pybind11_state PROPERTIES
225INSTALL_RPATH "@loader_path"
226BUILD_WITH_INSTALL_RPATH TRUE
227INSTALL_RPATH_USE_LINK_PATH FALSE)
228else()
229if (NOT CMAKE_SYSTEM_NAME MATCHES "AIX")
230set_property(TARGET onnxruntime_pybind11_state APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker -rpath=\\$ORIGIN")
231endif()
232endif()
233
234if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
235set(onnxruntime_CUSTOM_EXTERNAL_LIBRARIES "${onnxruntime_EXTERNAL_LIBRARIES}")
236list(FIND onnxruntime_CUSTOM_EXTERNAL_LIBRARIES onnx ONNX_INDEX)
237list(FIND onnxruntime_CUSTOM_EXTERNAL_LIBRARIES ${PROTOBUF_LIB} PROTOBUF_INDEX)
238MATH(EXPR PROTOBUF_INDEX_NEXT "${PROTOBUF_INDEX} + 1")
239if (ONNX_INDEX GREATER_EQUAL 0 AND PROTOBUF_INDEX GREATER_EQUAL 0)
240# Expect protobuf to follow onnx due to dependence
241list(INSERT onnxruntime_CUSTOM_EXTERNAL_LIBRARIES ${ONNX_INDEX} "-Wl,--no-as-needed")
242list(INSERT onnxruntime_CUSTOM_EXTERNAL_LIBRARIES ${PROTOBUF_INDEX_NEXT} "-Wl,--as-needed")
243else()
244message(FATAL_ERROR "Required external libraries onnx and protobuf are not found in onnxruntime_EXTERNAL_LIBRARIES")
245endif()
246target_link_libraries(onnxruntime_pybind11_state PRIVATE ${onnxruntime_CUSTOM_EXTERNAL_LIBRARIES})
247else()
248target_link_libraries(onnxruntime_pybind11_state PRIVATE ${onnxruntime_EXTERNAL_LIBRARIES})
249endif()
250
251set_target_properties(onnxruntime_pybind11_state PROPERTIES PREFIX "")
252set_target_properties(onnxruntime_pybind11_state PROPERTIES FOLDER "ONNXRuntime")
253if(onnxruntime_ENABLE_LTO)
254set_target_properties(onnxruntime_pybind11_state PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
255set_target_properties(onnxruntime_pybind11_state PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
256set_target_properties(onnxruntime_pybind11_state PROPERTIES INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL TRUE)
257endif()
258if (MSVC)
259set_target_properties(onnxruntime_pybind11_state PROPERTIES SUFFIX ".pyd")
260else()
261set_target_properties(onnxruntime_pybind11_state PROPERTIES SUFFIX ".so")
262endif()
263
264# Generate version_info.py in Windows build.
265# Has to be done before onnxruntime_python_srcs is set.
266if (WIN32)
267set(VERSION_INFO_FILE "${ONNXRUNTIME_ROOT}/python/version_info.py")
268
269if (onnxruntime_USE_CUDA)
270file(WRITE "${VERSION_INFO_FILE}" "use_cuda = True\n")
271if(onnxruntime_CUDNN_HOME)
272file(GLOB CUDNN_DLL_PATH "${onnxruntime_CUDNN_HOME}/bin/cudnn64_*.dll")
273if (NOT CUDNN_DLL_PATH)
274message(FATAL_ERROR "cuDNN not found in ${onnxruntime_CUDNN_HOME}")
275endif()
276else()
277file(GLOB CUDNN_DLL_PATH "${onnxruntime_CUDA_HOME}/bin/cudnn64_*.dll")
278if (NOT CUDNN_DLL_PATH)
279message(FATAL_ERROR "cuDNN not found in ${onnxruntime_CUDA_HOME}")
280endif()
281endif()
282get_filename_component(CUDNN_DLL_NAME ${CUDNN_DLL_PATH} NAME_WE)
283string(REPLACE "cudnn64_" "" CUDNN_VERSION "${CUDNN_DLL_NAME}")
284if(NOT onnxruntime_CUDA_VERSION)
285set(onnxruntime_CUDA_VERSION ${CUDAToolkit_VERSION})
286message("onnxruntime_CUDA_VERSION=${onnxruntime_CUDA_VERSION}")
287endif()
288file(APPEND "${VERSION_INFO_FILE}"
289"cuda_version = \"${onnxruntime_CUDA_VERSION}\"\n"
290"cudnn_version = \"${CUDNN_VERSION}\"\n"
291)
292else()
293file(WRITE "${VERSION_INFO_FILE}" "use_cuda = False\n")
294endif()
295
296if ("${MSVC_TOOLSET_VERSION}" STREQUAL "142")
297file(APPEND "${VERSION_INFO_FILE}" "vs2019 = True\n")
298else()
299file(APPEND "${VERSION_INFO_FILE}" "vs2019 = False\n")
300endif()
301endif()
302
303file(GLOB onnxruntime_backend_srcs CONFIGURE_DEPENDS
304"${ONNXRUNTIME_ROOT}/python/backend/*.py"
305)
306
307if (onnxruntime_ENABLE_TRAINING)
308file(GLOB onnxruntime_python_srcs CONFIGURE_DEPENDS
309"${ONNXRUNTIME_ROOT}/python/*.py"
310"${ORTTRAINING_SOURCE_DIR}/python/*.py"
311)
312else()
313file(GLOB onnxruntime_python_srcs CONFIGURE_DEPENDS
314"${ONNXRUNTIME_ROOT}/python/*.py"
315)
316endif()
317
318# Generate _pybind_state.py from _pybind_state.py.in replacing macros with either setdlopenflags or ""
319if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
320set(ONNXRUNTIME_SETDLOPENFLAGS_GLOBAL "sys.setdlopenflags(os.RTLD_GLOBAL|os.RTLD_NOW|os.RTLD_DEEPBIND)")
321set(ONNXRUNTIME_SETDLOPENFLAGS_LOCAL "sys.setdlopenflags(os.RTLD_LOCAL|os.RTLD_NOW|os.RTLD_DEEPBIND)")
322else()
323set(ONNXRUNTIME_SETDLOPENFLAGS_GLOBAL "")
324set(ONNXRUNTIME_SETDLOPENFLAGS_LOCAL "")
325endif()
326
327if (onnxruntime_ENABLE_LAZY_TENSOR)
328# Import torch so that onnxruntime's pybind can see its DLLs.
329set(ONNXRUNTIME_IMPORT_PYTORCH_TO_RESOLVE_DLLS "import torch")
330else()
331set(ONNXRUNTIME_IMPORT_PYTORCH_TO_RESOLVE_DLLS "")
332endif()
333
334configure_file(${ONNXRUNTIME_ROOT}/python/_pybind_state.py.in
335${CMAKE_BINARY_DIR}/onnxruntime/capi/_pybind_state.py)
336
337if (onnxruntime_ENABLE_TRAINING)
338file(GLOB onnxruntime_python_root_srcs CONFIGURE_DEPENDS
339"${ORTTRAINING_SOURCE_DIR}/python/training/*.py"
340)
341file(GLOB onnxruntime_python_amp_srcs CONFIGURE_DEPENDS
342"${ORTTRAINING_SOURCE_DIR}/python/training/amp/*.py"
343)
344file(GLOB onnxruntime_python_experimental_srcs CONFIGURE_DEPENDS
345"${ORTTRAINING_SOURCE_DIR}/python/training/experimental/*.py"
346)
347file(GLOB onnxruntime_python_gradient_graph_srcs CONFIGURE_DEPENDS
348"${ORTTRAINING_SOURCE_DIR}/python/training/experimental/gradient_graph/*.py"
349)
350file(GLOB onnxruntime_python_optim_srcs CONFIGURE_DEPENDS
351"${ORTTRAINING_SOURCE_DIR}/python/training/optim/*.py"
352)
353file(GLOB onnxruntime_python_ortmodule_srcs CONFIGURE_DEPENDS
354"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/*.py"
355)
356file(GLOB onnxruntime_python_ortmodule_experimental_srcs CONFIGURE_DEPENDS
357"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/experimental/*.py"
358)
359file(GLOB onnxruntime_python_ortmodule_experimental_json_config_srcs CONFIGURE_DEPENDS
360"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/experimental/json_config/*.py"
361)
362file(GLOB onnxruntime_python_ortmodule_experimental_hierarchical_srcs CONFIGURE_DEPENDS
363"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/experimental/hierarchical_ortmodule/*.py"
364)
365file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_srcs CONFIGURE_DEPENDS
366"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/*.py"
367)
368file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_aten_op_executor_srcs CONFIGURE_DEPENDS
369"${ONNXRUNTIME_ROOT}/python/torch_cpp_extensions/aten_op_executor/*"
370)
371file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_torch_interop_utils_srcs CONFIGURE_DEPENDS
372"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils/*"
373)
374file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_torch_gpu_allocator_srcs CONFIGURE_DEPENDS
375"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/cuda/torch_gpu_allocator/*"
376)
377file(GLOB onnxruntime_python_ortmodule_torch_cpp_ext_fused_ops_srcs CONFIGURE_DEPENDS
378"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/torch_cpp_extensions/cuda/fused_ops/*"
379)
380file(GLOB onnxruntime_python_ortmodule_graph_optimizers_srcs CONFIGURE_DEPENDS
381"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/graph_optimizers/*"
382)
383file(GLOB onnxruntime_python_ortmodule_pipe_srcs CONFIGURE_DEPENDS
384"${ORTTRAINING_SOURCE_DIR}/python/training/ortmodule/experimental/pipe/*"
385)
386file(GLOB onnxruntime_python_ort_triton_srcs CONFIGURE_DEPENDS
387"${ORTTRAINING_SOURCE_DIR}/python/training/ort_triton/*.py"
388)
389file(GLOB onnxruntime_python_ort_triton_kernel_srcs CONFIGURE_DEPENDS
390"${ORTTRAINING_SOURCE_DIR}/python/training/ort_triton/kernel/*.py"
391)
392file(GLOB onnxruntime_python_utils_srcs CONFIGURE_DEPENDS
393"${ORTTRAINING_SOURCE_DIR}/python/training/utils/*.py"
394)
395file(GLOB onnxruntime_python_utils_data_srcs CONFIGURE_DEPENDS
396"${ORTTRAINING_SOURCE_DIR}/python/training/utils/data/*"
397)
398file(GLOB onnxruntime_python_utils_hooks_srcs CONFIGURE_DEPENDS
399"${ORTTRAINING_SOURCE_DIR}/python/training/utils/hooks/*"
400)
401if (onnxruntime_ENABLE_TRAINING_APIS)
402file(GLOB onnxruntime_python_onnxblock_srcs CONFIGURE_DEPENDS
403"${ORTTRAINING_SOURCE_DIR}/python/training/onnxblock/*"
404)
405file(GLOB onnxruntime_python_onnxblock_loss_srcs CONFIGURE_DEPENDS
406"${ORTTRAINING_SOURCE_DIR}/python/training/onnxblock/loss/*"
407)
408file(GLOB onnxruntime_python_api_srcs CONFIGURE_DEPENDS
409"${ORTTRAINING_SOURCE_DIR}/python/training/api/*"
410)
411file(GLOB onnxruntime_python_onnxblock_optim_srcs CONFIGURE_DEPENDS
412"${ORTTRAINING_SOURCE_DIR}/python/training/onnxblock/optim/*"
413)
414endif()
415endif()
416
417if (onnxruntime_BUILD_UNIT_TESTS)
418file(GLOB onnxruntime_python_test_srcs CONFIGURE_DEPENDS
419"${ONNXRUNTIME_ROOT}/test/python/*.py"
420"${ORTTRAINING_SOURCE_DIR}/test/python/*.py"
421"${ORTTRAINING_SOURCE_DIR}/test/python/*.json"
422)
423file(GLOB onnxruntime_python_quantization_test_srcs CONFIGURE_DEPENDS
424"${ONNXRUNTIME_ROOT}/test/python/quantization/*.py"
425)
426file(GLOB onnxruntime_python_transformers_test_srcs CONFIGURE_DEPENDS
427"${ONNXRUNTIME_ROOT}/test/python/transformers/*.py"
428)
429file(GLOB onnxruntime_python_transformers_testdata_srcs CONFIGURE_DEPENDS
430"${ONNXRUNTIME_ROOT}/test/python/transformers/test_data/models/*.onnx"
431)
432file(GLOB onnxruntime_python_transformers_testdata_whisper CONFIGURE_DEPENDS
433"${ONNXRUNTIME_ROOT}/test/python/transformers/test_data/models/whisper/*.onnx"
434)
435file(GLOB onnxruntime_python_transformers_testdata_conformer CONFIGURE_DEPENDS
436"${ONNXRUNTIME_ROOT}/test/python/transformers/test_data/models/conformer/*.onnx"
437)
438endif()
439
440file(GLOB onnxruntime_python_tools_srcs CONFIGURE_DEPENDS
441"${ONNXRUNTIME_ROOT}/python/tools/*.py"
442)
443file(GLOB onnxruntime_python_quantization_src CONFIGURE_DEPENDS
444"${ONNXRUNTIME_ROOT}/python/tools/quantization/*.py"
445)
446file(GLOB onnxruntime_python_quantization_operators_src CONFIGURE_DEPENDS
447"${ONNXRUNTIME_ROOT}/python/tools/quantization/operators/*.py"
448)
449file(GLOB onnxruntime_python_quantization_cal_table_flatbuffers_src CONFIGURE_DEPENDS
450"${ONNXRUNTIME_ROOT}/python/tools/quantization/CalTableFlatBuffers/*.py"
451)
452file(GLOB onnxruntime_python_quantization_fusions_src CONFIGURE_DEPENDS
453"${ONNXRUNTIME_ROOT}/python/tools/quantization/fusions/*.py"
454)
455file(GLOB onnxruntime_python_quantization_ep_qnn_src CONFIGURE_DEPENDS
456"${ONNXRUNTIME_ROOT}/python/tools/quantization/execution_providers/qnn/*.py"
457)
458file(GLOB onnxruntime_python_transformers_src CONFIGURE_DEPENDS
459"${ONNXRUNTIME_ROOT}/python/tools/transformers/*.py"
460)
461file(GLOB onnxruntime_python_transformers_models_bart_src CONFIGURE_DEPENDS
462"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/bart/*.py"
463)
464file(GLOB onnxruntime_python_transformers_models_bert_src CONFIGURE_DEPENDS
465"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/bert/*.py"
466)
467file(GLOB onnxruntime_python_transformers_models_gpt2_src CONFIGURE_DEPENDS
468"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/gpt2/*.py"
469)
470file(GLOB onnxruntime_python_transformers_models_llama_src CONFIGURE_DEPENDS
471"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/llama/*.py"
472)
473file(GLOB onnxruntime_python_transformers_models_longformer_src CONFIGURE_DEPENDS
474"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/longformer/*.py"
475)
476file(GLOB onnxruntime_python_transformers_models_phi2_src CONFIGURE_DEPENDS
477"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/phi2/*.py"
478)
479file(GLOB onnxruntime_python_transformers_models_stable_diffusion_src CONFIGURE_DEPENDS
480"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/stable_diffusion/*.py"
481)
482file(GLOB onnxruntime_python_transformers_models_t5_src CONFIGURE_DEPENDS
483"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/t5/*.py"
484)
485file(GLOB onnxruntime_python_transformers_models_whisper_src CONFIGURE_DEPENDS
486"${ONNXRUNTIME_ROOT}/python/tools/transformers/models/whisper/*.py"
487)
488file(GLOB onnxruntime_python_datasets_srcs CONFIGURE_DEPENDS
489"${ONNXRUNTIME_ROOT}/python/datasets/*.py"
490)
491file(GLOB onnxruntime_python_datasets_data CONFIGURE_DEPENDS
492"${ONNXRUNTIME_ROOT}/python/datasets/*.pb"
493"${ONNXRUNTIME_ROOT}/python/datasets/*.onnx"
494)
495
496# ORT Mobile helpers to convert ONNX model to ORT format, analyze model for suitability in mobile scenarios,
497# and assist with export from PyTorch.
498set(onnxruntime_mobile_util_srcs
499${REPO_ROOT}/tools/python/util/check_onnx_model_mobile_usability.py
500${REPO_ROOT}/tools/python/util/convert_onnx_models_to_ort.py
501${REPO_ROOT}/tools/python/util/file_utils.py
502${REPO_ROOT}/tools/python/util/logger.py
503${REPO_ROOT}/tools/python/util/make_dynamic_shape_fixed.py
504${REPO_ROOT}/tools/python/util/onnx_model_utils.py
505${REPO_ROOT}/tools/python/util/optimize_onnx_model.py
506${REPO_ROOT}/tools/python/util/pytorch_export_helpers.py
507${REPO_ROOT}/tools/python/util/reduced_build_config_parser.py
508${REPO_ROOT}/tools/python/util/update_onnx_opset.py
509)
510file(GLOB onnxruntime_ort_format_model_srcs CONFIGURE_DEPENDS
511${REPO_ROOT}/tools/python/util/ort_format_model/*.py
512)
513file(GLOB onnxruntime_mobile_helpers_srcs CONFIGURE_DEPENDS
514${REPO_ROOT}/tools/python/util/mobile_helpers/*.py
515${REPO_ROOT}/tools/ci_build/github/android/nnapi_supported_ops.md
516${REPO_ROOT}/tools/ci_build/github/apple/coreml_supported_mlprogram_ops.md
517${REPO_ROOT}/tools/ci_build/github/apple/coreml_supported_neuralnetwork_ops.md
518)
519file(GLOB onnxruntime_qdq_helper_srcs CONFIGURE_DEPENDS
520${REPO_ROOT}/tools/python/util/qdq_helpers/*.py
521)
522
523if (onnxruntime_USE_OPENVINO)
524file(GLOB onnxruntime_python_openvino_python_srcs CONFIGURE_DEPENDS
525${REPO_ROOT}/tools/python/util/add_openvino_win_libs.py
526)
527endif()
528
529set(build_output_target onnxruntime_common)
530if(NOT onnxruntime_ENABLE_STATIC_ANALYSIS)
531add_custom_command(
532TARGET onnxruntime_pybind11_state POST_BUILD
533COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/backend
534COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi
535COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/training
536COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/datasets
537COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools
538COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/mobile_helpers
539COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/qdq_helpers
540COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/ort_format_model
541COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/ort_format_model/ort_flatbuffers_py
542COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers
543COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models
544COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/bart
545COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/bert
546COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/gpt2
547COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/llama
548COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/longformer
549COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/phi2
550COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/stable_diffusion
551COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/t5
552COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/whisper
553COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization
554COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/operators
555COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/CalTableFlatBuffers
556COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/fusions
557COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/execution_providers
558COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/execution_providers/qnn
559COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/quantization
560COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/transformers
561COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models
562COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models/whisper
563COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/eager_test
564COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models/conformer
565COMMAND ${CMAKE_COMMAND} -E copy
566${ONNXRUNTIME_ROOT}/__init__.py
567$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/
568COMMAND ${CMAKE_COMMAND} -E copy
569${REPO_ROOT}/requirements.txt
570$<TARGET_FILE_DIR:${build_output_target}>
571COMMAND ${CMAKE_COMMAND} -E copy
572${REPO_ROOT}/ThirdPartyNotices.txt
573$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/
574COMMAND ${CMAKE_COMMAND} -E copy
575${REPO_ROOT}/docs/Privacy.md
576$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/
577COMMAND ${CMAKE_COMMAND} -E copy
578${REPO_ROOT}/LICENSE
579$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/
580COMMAND ${CMAKE_COMMAND} -E copy
581${onnxruntime_backend_srcs}
582$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/backend/
583COMMAND ${CMAKE_COMMAND} -E copy
584${onnxruntime_python_srcs}
585$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
586COMMAND ${CMAKE_COMMAND} -E copy_if_different
587${CMAKE_BINARY_DIR}/onnxruntime/capi/_pybind_state.py
588$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
589COMMAND ${CMAKE_COMMAND} -E copy
590$<TARGET_FILE:onnxruntime_pybind11_state>
591$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
592COMMAND ${CMAKE_COMMAND} -E copy
593${onnxruntime_python_datasets_srcs}
594$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/datasets/
595COMMAND ${CMAKE_COMMAND} -E copy
596${onnxruntime_python_datasets_data}
597$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/datasets/
598COMMAND ${CMAKE_COMMAND} -E copy
599${onnxruntime_python_tools_srcs}
600$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/
601COMMAND ${CMAKE_COMMAND} -E copy
602${onnxruntime_mobile_util_srcs}
603$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/
604# append the /tools/python/utils imports to the __init__.py that came from /onnxruntime/tools.
605# we're aggregating scripts from two different locations, and only include selected functionality from
606# /tools/python/util. due to that we take the full __init__.py from /onnxruntime/tools and append
607# the required content from /tools/python/util/__init__append.py.
608COMMAND ${CMAKE_COMMAND} -E cat
609${REPO_ROOT}/tools/python/util/__init__append.py >>
610$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/__init__.py
611COMMAND ${CMAKE_COMMAND} -E copy
612${onnxruntime_qdq_helper_srcs}
613$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/qdq_helpers/
614COMMAND ${CMAKE_COMMAND} -E copy
615${onnxruntime_mobile_helpers_srcs}
616$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/mobile_helpers/
617COMMAND ${CMAKE_COMMAND} -E copy
618${onnxruntime_ort_format_model_srcs}
619$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/ort_format_model/
620COMMAND ${CMAKE_COMMAND} -E copy_directory
621${ONNXRUNTIME_ROOT}/core/flatbuffers/ort_flatbuffers_py
622$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/ort_format_model/ort_flatbuffers_py
623COMMAND ${CMAKE_COMMAND} -E copy
624${onnxruntime_python_quantization_src}
625$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/
626COMMAND ${CMAKE_COMMAND} -E copy
627${onnxruntime_python_quantization_operators_src}
628$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/operators/
629COMMAND ${CMAKE_COMMAND} -E copy
630${onnxruntime_python_quantization_cal_table_flatbuffers_src}
631$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/CalTableFlatBuffers/
632COMMAND ${CMAKE_COMMAND} -E copy
633${onnxruntime_python_quantization_fusions_src}
634$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/fusions/
635COMMAND ${CMAKE_COMMAND} -E copy
636${onnxruntime_python_quantization_ep_qnn_src}
637$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/quantization/execution_providers/qnn/
638COMMAND ${CMAKE_COMMAND} -E copy
639${onnxruntime_python_transformers_src}
640$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/
641COMMAND ${CMAKE_COMMAND} -E copy
642${onnxruntime_python_transformers_models_bart_src}
643$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/bart/
644COMMAND ${CMAKE_COMMAND} -E copy
645${onnxruntime_python_transformers_models_bert_src}
646$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/bert/
647COMMAND ${CMAKE_COMMAND} -E copy
648${onnxruntime_python_transformers_models_gpt2_src}
649$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/gpt2/
650COMMAND ${CMAKE_COMMAND} -E copy
651${onnxruntime_python_transformers_models_llama_src}
652$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/llama/
653COMMAND ${CMAKE_COMMAND} -E copy
654${onnxruntime_python_transformers_models_longformer_src}
655$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/longformer/
656COMMAND ${CMAKE_COMMAND} -E copy
657${onnxruntime_python_transformers_models_phi2_src}
658$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/phi2/
659COMMAND ${CMAKE_COMMAND} -E copy
660${onnxruntime_python_transformers_models_stable_diffusion_src}
661$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/stable_diffusion/
662COMMAND ${CMAKE_COMMAND} -E copy
663${onnxruntime_python_transformers_models_t5_src}
664$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/t5/
665COMMAND ${CMAKE_COMMAND} -E copy
666${onnxruntime_python_transformers_models_whisper_src}
667$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/transformers/models/whisper/
668COMMAND ${CMAKE_COMMAND} -E copy
669${REPO_ROOT}/VERSION_NUMBER
670$<TARGET_FILE_DIR:${build_output_target}>
671)
672
673if (onnxruntime_BUILD_SHARED_LIB)
674add_custom_command(
675TARGET onnxruntime_pybind11_state POST_BUILD
676COMMAND ${CMAKE_COMMAND} -E copy
677$<TARGET_FILE:onnxruntime>
678$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
679)
680endif()
681
682if (onnxruntime_USE_OPENVINO)
683add_custom_command(
684TARGET onnxruntime_pybind11_state POST_BUILD
685COMMAND ${CMAKE_COMMAND} -E copy
686${onnxruntime_python_openvino_python_srcs}
687$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/tools/
688)
689endif()
690
691if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS)
692add_custom_command(
693TARGET onnxruntime_pybind11_state POST_BUILD
694COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/external/include/
695COMMAND ${CMAKE_COMMAND} -E create_symlink
696$<TARGET_FILE_DIR:${build_output_target}>/include/google
697$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/external/include/google
698COMMAND ${CMAKE_COMMAND} -E create_symlink
699$<TARGET_FILE_DIR:${build_output_target}>/external/onnx/onnx
700$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/external/include/onnx
701COMMAND ${CMAKE_COMMAND} -E copy_directory
702${ORTTRAINING_ROOT}/orttraining/test/external_custom_ops
703$<TARGET_FILE_DIR:${build_output_target}>/external_custom_ops
704)
705endif()
706
707if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD
708AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS|visionOS"
709AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android"
710AND NOT onnxruntime_USE_ROCM
711AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
712add_custom_command(
713TARGET onnxruntime_pybind11_state POST_BUILD
714COMMAND ${CMAKE_COMMAND} -E copy
715$<TARGET_FILE:onnxruntime_providers_shared>
716$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
717)
718endif()
719
720if (onnxruntime_BUILD_UNIT_TESTS)
721add_custom_command(
722TARGET onnxruntime_pybind11_state POST_BUILD
723COMMAND ${CMAKE_COMMAND} -E copy
724${onnxruntime_python_test_srcs}
725$<TARGET_FILE_DIR:${build_output_target}>
726COMMAND ${CMAKE_COMMAND} -E copy
727${onnxruntime_python_quantization_test_srcs}
728$<TARGET_FILE_DIR:${build_output_target}>/quantization/
729COMMAND ${CMAKE_COMMAND} -E copy
730${onnxruntime_python_transformers_test_srcs}
731$<TARGET_FILE_DIR:${build_output_target}>/transformers/
732COMMAND ${CMAKE_COMMAND} -E copy
733${onnxruntime_python_transformers_testdata_srcs}
734$<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models/
735COMMAND ${CMAKE_COMMAND} -E copy
736${onnxruntime_python_transformers_testdata_whisper}
737$<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models/whisper/
738COMMAND ${CMAKE_COMMAND} -E copy
739${onnxruntime_python_transformers_testdata_conformer}
740$<TARGET_FILE_DIR:${build_output_target}>/transformers/test_data/models/conformer/
741)
742endif()
743
744if (onnxruntime_BUILD_UNIT_TESTS AND onnxruntime_ENABLE_EAGER_MODE)
745file(GLOB onnxruntime_eager_test_srcs CONFIGURE_DEPENDS
746"${ORTTRAINING_ROOT}/orttraining/eager/test/*.py"
747)
748add_custom_command(
749TARGET onnxruntime_pybind11_state POST_BUILD
750COMMAND ${CMAKE_COMMAND} -E copy
751${onnxruntime_eager_test_srcs}
752$<TARGET_FILE_DIR:${build_output_target}>/eager_test/
753)
754endif()
755
756if (onnxruntime_ENABLE_TRAINING)
757add_custom_command(
758TARGET onnxruntime_pybind11_state POST_BUILD
759COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training
760COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/amp
761COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/experimental
762COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/experimental/gradient_graph
763COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/optim
764COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule
765COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental
766COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/json_config
767COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/hierarchical_ortmodule
768COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions
769COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cpu/aten_op_executor
770COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils
771COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cuda/torch_gpu_allocator
772COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cuda/fused_ops
773COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/graph_optimizers
774COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/pipe
775COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ort_triton
776COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ort_triton/kernel
777COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils
778COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils/data/
779COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils/hooks/
780COMMAND ${CMAKE_COMMAND} -E copy
781${onnxruntime_python_root_srcs}
782$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/
783COMMAND ${CMAKE_COMMAND} -E copy
784${onnxruntime_python_amp_srcs}
785$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/amp/
786COMMAND ${CMAKE_COMMAND} -E copy
787${onnxruntime_python_experimental_srcs}
788$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/experimental/
789COMMAND ${CMAKE_COMMAND} -E copy
790${onnxruntime_python_gradient_graph_srcs}
791$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/experimental/gradient_graph/
792COMMAND ${CMAKE_COMMAND} -E copy
793${onnxruntime_python_optim_srcs}
794$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/optim/
795COMMAND ${CMAKE_COMMAND} -E copy
796${onnxruntime_python_ortmodule_srcs}
797$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/
798COMMAND ${CMAKE_COMMAND} -E copy
799${onnxruntime_python_ortmodule_experimental_srcs}
800$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/
801COMMAND ${CMAKE_COMMAND} -E copy
802${onnxruntime_python_ortmodule_experimental_json_config_srcs}
803$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/json_config/
804COMMAND ${CMAKE_COMMAND} -E copy
805${onnxruntime_python_ortmodule_experimental_hierarchical_srcs}
806$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/hierarchical_ortmodule/
807COMMAND ${CMAKE_COMMAND} -E copy
808${onnxruntime_python_ortmodule_torch_cpp_ext_srcs}
809$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/
810COMMAND ${CMAKE_COMMAND} -E copy
811${onnxruntime_python_ortmodule_torch_cpp_ext_aten_op_executor_srcs}
812$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cpu/aten_op_executor/
813COMMAND ${CMAKE_COMMAND} -E copy
814${onnxruntime_python_ortmodule_torch_cpp_ext_torch_interop_utils_srcs}
815$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cpu/torch_interop_utils/
816COMMAND ${CMAKE_COMMAND} -E copy
817${onnxruntime_python_ortmodule_torch_cpp_ext_torch_gpu_allocator_srcs}
818$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cuda/torch_gpu_allocator/
819COMMAND ${CMAKE_COMMAND} -E copy
820${onnxruntime_python_ortmodule_torch_cpp_ext_fused_ops_srcs}
821$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/torch_cpp_extensions/cuda/fused_ops/
822COMMAND ${CMAKE_COMMAND} -E copy
823${onnxruntime_python_ortmodule_graph_optimizers_srcs}
824$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/graph_optimizers/
825COMMAND ${CMAKE_COMMAND} -E copy
826${onnxruntime_python_ortmodule_pipe_srcs}
827$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ortmodule/experimental/pipe/
828COMMAND ${CMAKE_COMMAND} -E copy
829${onnxruntime_python_ort_triton_srcs}
830$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ort_triton/
831COMMAND ${CMAKE_COMMAND} -E copy
832${onnxruntime_python_ort_triton_kernel_srcs}
833$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/ort_triton/kernel/
834COMMAND ${CMAKE_COMMAND} -E copy
835${onnxruntime_python_utils_srcs}
836$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils/
837COMMAND ${CMAKE_COMMAND} -E copy
838${onnxruntime_python_utils_data_srcs}
839$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils/data/
840COMMAND ${CMAKE_COMMAND} -E copy
841${onnxruntime_python_utils_hooks_srcs}
842$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/utils/hooks/
843)
844if (onnxruntime_ENABLE_TRAINING_APIS)
845add_custom_command(
846TARGET onnxruntime_pybind11_state POST_BUILD
847COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock
848COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock/loss
849COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock/optim
850COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/api
851COMMAND ${CMAKE_COMMAND} -E copy
852${onnxruntime_python_onnxblock_srcs}
853$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock/
854COMMAND ${CMAKE_COMMAND} -E copy
855${onnxruntime_python_onnxblock_loss_srcs}
856$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock/loss/
857COMMAND ${CMAKE_COMMAND} -E copy
858${onnxruntime_python_onnxblock_optim_srcs}
859$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/onnxblock/optim/
860COMMAND ${CMAKE_COMMAND} -E copy
861${onnxruntime_python_api_srcs}
862$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/training/api/
863)
864endif()
865endif()
866
867if (onnxruntime_USE_DNNL)
868add_custom_command(
869TARGET onnxruntime_pybind11_state POST_BUILD
870COMMAND ${CMAKE_COMMAND} -E copy
871${DNNL_DLL_PATH} $<TARGET_FILE:onnxruntime_providers_dnnl>
872$<TARGET_FILE:onnxruntime_providers_shared>
873$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
874)
875endif()
876
877if (onnxruntime_USE_VITISAI)
878add_custom_command(
879TARGET onnxruntime_pybind11_state POST_BUILD
880COMMAND ${CMAKE_COMMAND} -E copy
881${DNNL_DLL_PATH} $<TARGET_FILE:onnxruntime_providers_vitisai>
882$<TARGET_FILE:onnxruntime_providers_shared>
883$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
884)
885endif()
886
887if (onnxruntime_USE_TENSORRT)
888add_custom_command(
889TARGET onnxruntime_pybind11_state POST_BUILD
890COMMAND ${CMAKE_COMMAND} -E copy
891$<TARGET_FILE:onnxruntime_providers_tensorrt>
892$<TARGET_FILE:onnxruntime_providers_shared>
893$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
894)
895endif()
896
897if (onnxruntime_USE_MIGRAPHX)
898add_custom_command(
899TARGET onnxruntime_pybind11_state POST_BUILD
900COMMAND ${CMAKE_COMMAND} -E copy
901$<TARGET_FILE:onnxruntime_providers_migraphx>
902$<TARGET_FILE:onnxruntime_providers_shared>
903$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
904)
905endif()
906
907if (onnxruntime_USE_OPENVINO)
908add_custom_command(
909TARGET onnxruntime_pybind11_state POST_BUILD
910COMMAND ${CMAKE_COMMAND} -E copy
911$<TARGET_FILE:onnxruntime_providers_openvino>
912$<TARGET_FILE:onnxruntime_providers_shared>
913$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
914)
915endif()
916
917if (DEFINED ENV{OPENVINO_MANYLINUX})
918file(GLOB onnxruntime_python_openvino_python_srcs CONFIGURE_DEPENDS
919"${ONNXRUNTIME_ROOT}/core/providers/openvino/scripts/*"
920)
921
922add_custom_command(
923TARGET onnxruntime_pybind11_state POST_BUILD
924COMMAND ${CMAKE_COMMAND} -E copy
925${onnxruntime_python_openvino_python_srcs}
926$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
927)
928endif()
929
930if (onnxruntime_USE_CUDA)
931add_custom_command(
932TARGET onnxruntime_pybind11_state POST_BUILD
933COMMAND ${CMAKE_COMMAND} -E copy
934$<TARGET_FILE:onnxruntime_providers_cuda>
935$<TARGET_FILE:onnxruntime_providers_shared>
936$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
937)
938endif()
939
940if (onnxruntime_USE_CANN)
941add_custom_command(
942TARGET onnxruntime_pybind11_state POST_BUILD
943COMMAND ${CMAKE_COMMAND} -E copy
944$<TARGET_FILE:onnxruntime_providers_cann>
945$<TARGET_FILE:onnxruntime_providers_shared>
946$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
947)
948endif()
949
950if (onnxruntime_USE_ROCM)
951add_custom_command(
952TARGET onnxruntime_pybind11_state POST_BUILD
953COMMAND ${CMAKE_COMMAND} -E copy
954$<TARGET_FILE:onnxruntime_providers_rocm>
955$<TARGET_FILE:onnxruntime_providers_shared>
956$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
957)
958endif()
959
960if (onnxruntime_USE_TVM)
961file(GLOB onnxruntime_python_providers_tvm_srcs CONFIGURE_DEPENDS
962"${ONNXRUNTIME_ROOT}/python/providers/tvm/*.py"
963)
964add_custom_command(
965TARGET onnxruntime_pybind11_state POST_BUILD
966COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/providers
967COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/providers/tvm
968COMMAND ${CMAKE_COMMAND} -E copy
969${onnxruntime_python_providers_tvm_srcs}
970$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/providers/tvm
971COMMAND ${CMAKE_COMMAND} -E copy
972$<TARGET_FILE:onnxruntime_providers_tvm>
973$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
974)
975
976add_custom_command(
977TARGET onnxruntime_pybind11_state POST_BUILD
978WORKING_DIRECTORY ${tvm_SOURCE_DIR}/python
979COMMAND ${Python_EXECUTABLE} setup.py bdist_wheel
980)
981
982add_custom_command(
983TARGET onnxruntime_pybind11_state POST_BUILD
984COMMAND ${Python_EXECUTABLE}
985$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/providers/tvm/extend_python_file.py
986--target_file $<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/_ld_preload.py
987)
988
989endif()
990
991if (onnxruntime_USE_DML)
992if (NOT onnxruntime_USE_CUSTOM_DIRECTML)
993set(dml_shared_lib_path ${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}-win/${DML_SHARED_LIB})
994else()
995set(dml_shared_lib_path ${DML_PACKAGE_DIR}/bin/${DML_SHARED_LIB})
996endif()
997add_custom_command(
998TARGET onnxruntime_pybind11_state POST_BUILD
999COMMAND ${CMAKE_COMMAND} -E copy
1000${dml_shared_lib_path}
1001$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
1002)
1003endif()
1004
1005if (onnxruntime_USE_NNAPI_BUILTIN)
1006add_custom_command(
1007TARGET onnxruntime_pybind11_state POST_BUILD
1008COMMAND ${CMAKE_COMMAND} -E copy
1009$<TARGET_FILE:onnxruntime_providers_nnapi>
1010$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
1011)
1012endif()
1013
1014if (onnxruntime_USE_COREML)
1015add_custom_command(
1016TARGET onnxruntime_pybind11_state POST_BUILD
1017COMMAND ${CMAKE_COMMAND} -E copy
1018$<TARGET_FILE:onnxruntime_providers_coreml>
1019$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
1020)
1021endif()
1022
1023if (onnxruntime_USE_QNN)
1024add_custom_command(
1025TARGET onnxruntime_pybind11_state POST_BUILD
1026COMMAND ${CMAKE_COMMAND} -E copy
1027${QNN_LIB_FILES}
1028$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/capi/
1029)
1030if (EXISTS "${onnxruntime_QNN_HOME}/Qualcomm AI Hub Proprietary License.pdf")
1031add_custom_command(
1032TARGET onnxruntime_pybind11_state POST_BUILD
1033COMMAND ${CMAKE_COMMAND} -E copy
1034"${onnxruntime_QNN_HOME}/Qualcomm AI Hub Proprietary License.pdf"
1035$<TARGET_FILE_DIR:${build_output_target}>/onnxruntime/
1036)
1037endif()
1038endif()
1039
1040endif()
1041