mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
* updated cmake files for trt * added trt execution provider * added trt basic test * removed trt_path action attribute * Add files via upload * Update build.py * Update trt_allocator.h * fixed issues found by reviewers * changed cast operator * added comment for custom kernel implementation * changed auto to auto& * changed to function compile APIs for TRT execution provider * changed to function compile APIs for TRT execution provider * added new DType DInt64 * adapted to the changes of onnxruntime_c_api * removed trt kernel (use function compile instead) * updated onnx-tensorrt submodule * set default memory type to TRT fused kernel * resolve merge conflict * fixed the issue that USE_CUDA conflicts with USE_TRT * construct graph by adding nodes in topological order * made changes for Windows * change buffers type * bypass HasImplementationOf check for TRT XP because TRT kernel is not registered * added domain to version info in rebuilt model proto * added trt to test option list * added DomainToVersionMap() to GraphViewer * removed Copy() * fixed broken code * format the code to clang format * used local reference to the frequently used values * fixed a couple of issues according to reviewers feedback * fixed a couple of issues according to reviewers feedback * added python binding for TRT and enable use_cuda when use_trt is on * fixed a redefinition issue * changed shared_ptr to unique_ptr on trt engines, and made a few changes required by reviewers * enabled trtexecution provider for unit tests * renamed trt to tensorrt * added tesorrt to python binding * update submodule onnx and onnx-tensorrt * made a couple of minor changes based on reviewer's feedback * added CUDA_CHECK * removed test code * fixed broken code after merge * updated onnx-tensorrt submodule * added post processing to align trt inputs/outputs with graph inputs/outputs * updated onnx submodule * added CUDA fallback for TensorRT and fixed TensorRT cmake issue * added ci pipeline for tensorrt and removed some redundent code from trt xp * fixed syntax issue * updated onnx-tensorrt submodule * fix trt build problem by: (#602) 1. Add additional /wd for debug build 2. Add io.h for additional targets 3. Bring back mb version of getopt * Update install_ubuntu.sh * Update linux-gpu-tensorrt-ci-pipeline.yml * Update linux-gpu-tensorrt-ci-pipeline.yml * Update run_build.sh * Update run_build.sh * Update run_build.sh * Update run_build.sh * fixed the issue that GetKernelRegistry returns nullptr * merged master to this branch * moved some data types to private * fixed tensorrt CI pipeline issue * customized test data for TensorRT pipeline * added onnx-tensorrt in json file and fixed an issue in ci script * added comments
192 lines
7.4 KiB
CMake
192 lines
7.4 KiB
CMake
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
|
|
include(pybind11)
|
|
FIND_PACKAGE(NumPy)
|
|
|
|
if(NOT PYTHON_INCLUDE_DIR)
|
|
set(PYTHON_NOT_FOUND false)
|
|
exec_program("${PYTHON_EXECUTABLE}"
|
|
ARGS "-c \"import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())\""
|
|
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
|
|
RETURN_VALUE PYTHON_NOT_FOUND)
|
|
if(${PYTHON_NOT_FOUND})
|
|
message(FATAL_ERROR
|
|
"Cannot get Python include directory. Is distutils installed?")
|
|
endif(${PYTHON_NOT_FOUND})
|
|
endif(NOT PYTHON_INCLUDE_DIR)
|
|
|
|
# 2. Resolve the installed version of NumPy (for numpy/arrayobject.h).
|
|
if(NOT NUMPY_INCLUDE_DIR)
|
|
set(NUMPY_NOT_FOUND false)
|
|
exec_program("${PYTHON_EXECUTABLE}"
|
|
ARGS "-c \"import numpy; print(numpy.get_include())\""
|
|
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
|
|
RETURN_VALUE NUMPY_NOT_FOUND)
|
|
if(${NUMPY_NOT_FOUND})
|
|
message(FATAL_ERROR
|
|
"Cannot get NumPy include directory: Is NumPy installed?")
|
|
endif(${NUMPY_NOT_FOUND})
|
|
endif(NOT NUMPY_INCLUDE_DIR)
|
|
|
|
# ---[ Python + Numpy
|
|
set(onnxruntime_pybind_srcs_pattern
|
|
"${ONNXRUNTIME_ROOT}/python/*.cc"
|
|
"${ONNXRUNTIME_ROOT}/python/*.h"
|
|
)
|
|
|
|
file(GLOB onnxruntime_pybind_srcs ${onnxruntime_pybind_srcs_pattern})
|
|
|
|
#TODO(): enable cuda and test it
|
|
add_library(onnxruntime_pybind11_state MODULE ${onnxruntime_pybind_srcs})
|
|
if(HAS_CAST_FUNCTION_TYPE)
|
|
target_compile_options(onnxruntime_pybind11_state PRIVATE "-Wno-cast-function-type")
|
|
endif()
|
|
target_include_directories(onnxruntime_pybind11_state PRIVATE ${ONNXRUNTIME_ROOT} ${PYTHON_INCLUDE_DIR} ${NUMPY_INCLUDE_DIR})
|
|
target_include_directories(onnxruntime_pybind11_state PRIVATE ${pybind11_INCLUDE_DIRS})
|
|
onnxruntime_add_include_to_target(onnxruntime_pybind11_state gsl)
|
|
if(APPLE)
|
|
set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker -exported_symbols_list ${ONNXRUNTIME_ROOT}/python/exported_symbols.lst")
|
|
elseif(UNIX)
|
|
set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/python/version_script.lds -Xlinker --no-undefined")
|
|
else()
|
|
set(ONNXRUNTIME_SO_LINK_FLAG "-DEF:${ONNXRUNTIME_ROOT}/python/pybind.def")
|
|
endif()
|
|
|
|
set(onnxruntime_pybind11_state_libs
|
|
onnxruntime_session
|
|
${onnxruntime_libs}
|
|
${PROVIDERS_CUDA}
|
|
${PROVIDERS_MKLDNN}
|
|
${PROVIDERS_TENSORRT}
|
|
onnxruntime_optimizer
|
|
onnxruntime_providers
|
|
onnxruntime_util
|
|
${onnxruntime_tvm_libs}
|
|
onnxruntime_framework
|
|
onnxruntime_util
|
|
onnxruntime_graph
|
|
onnxruntime_common
|
|
onnxruntime_mlas
|
|
)
|
|
|
|
set(onnxruntime_pybind11_state_dependencies
|
|
${onnxruntime_EXTERNAL_DEPENDENCIES}
|
|
pybind11
|
|
)
|
|
|
|
add_dependencies(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_dependencies})
|
|
if (MSVC)
|
|
# if MSVC, pybind11 looks for release version of python lib (pybind11/detail/common.h undefs _DEBUG)
|
|
target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} ${PYTHON_LIBRARY_RELEASE} ${ONNXRUNTIME_SO_LINK_FLAG} debug ${onnxruntime_EXTERNAL_LIBRARIES_DEBUG} optimized ${onnxruntime_EXTERNAL_LIBRARIES})
|
|
elseif (APPLE)
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
|
|
target_link_libraries(onnxruntime_pybind11_state ${onnxruntime_pybind11_state_libs} debug ${onnxruntime_EXTERNAL_LIBRARIES_DEBUG} optimized ${onnxruntime_EXTERNAL_LIBRARIES} ${ONNXRUNTIME_SO_LINK_FLAG})
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES
|
|
INSTALL_RPATH "@loader_path"
|
|
BUILD_WITH_INSTALL_RPATH TRUE
|
|
INSTALL_RPATH_USE_LINK_PATH FALSE)
|
|
else()
|
|
target_link_libraries(onnxruntime_pybind11_state PRIVATE ${onnxruntime_pybind11_state_libs} ${PYTHON_LIBRARY} ${ONNXRUNTIME_SO_LINK_FLAG} debug ${onnxruntime_EXTERNAL_LIBRARIES_DEBUG} optimized ${onnxruntime_EXTERNAL_LIBRARIES})
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES LINK_FLAGS "-Xlinker -rpath=\$ORIGIN")
|
|
endif()
|
|
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES PREFIX "")
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES FOLDER "ONNXRuntime")
|
|
|
|
if (MSVC)
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES SUFFIX ".pyd")
|
|
else()
|
|
set_target_properties(onnxruntime_pybind11_state PROPERTIES SUFFIX ".so")
|
|
endif()
|
|
|
|
file(GLOB onnxruntime_backend_srcs
|
|
"${ONNXRUNTIME_ROOT}/python/backend/*.py"
|
|
)
|
|
file(GLOB onnxruntime_python_srcs
|
|
"${ONNXRUNTIME_ROOT}/python/*.py"
|
|
)
|
|
file(GLOB onnxruntime_python_test_srcs
|
|
"${ONNXRUNTIME_ROOT}/test/python/*.py"
|
|
)
|
|
file(GLOB onnxruntime_python_tools_srcs
|
|
"${ONNXRUNTIME_ROOT}/python/tools/*.py"
|
|
)
|
|
file(GLOB onnxruntime_python_datasets_srcs
|
|
"${ONNXRUNTIME_ROOT}/python/datasets/*.py"
|
|
)
|
|
file(GLOB onnxruntime_python_datasets_data
|
|
"${ONNXRUNTIME_ROOT}/python/datasets/*.pb"
|
|
"${ONNXRUNTIME_ROOT}/python/datasets/*.onnx"
|
|
)
|
|
|
|
# adjust based on what target/s onnxruntime_unittests.cmake created
|
|
if (SingleUnitTestProject)
|
|
set(test_data_target onnxruntime_test_all)
|
|
else()
|
|
set(test_data_target onnxruntime_test_ir)
|
|
endif()
|
|
|
|
add_custom_command(
|
|
TARGET onnxruntime_pybind11_state POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/backend
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/datasets
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/tools
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${ONNXRUNTIME_ROOT}/__init__.py
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${REPO_ROOT}/ThirdPartyNotices.txt
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${REPO_ROOT}/LICENSE
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_python_test_srcs}
|
|
$<TARGET_FILE_DIR:${test_data_target}>
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_backend_srcs}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/backend/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_python_srcs}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
$<TARGET_FILE:onnxruntime_pybind11_state>
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_python_datasets_srcs}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/datasets/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_python_datasets_data}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/datasets/
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${onnxruntime_python_tools_srcs}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/tools/
|
|
)
|
|
|
|
if (onnxruntime_USE_MKLDNN)
|
|
add_custom_command(
|
|
TARGET onnxruntime_pybind11_state POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${MKLDNN_LIB_DIR}/${MKLDNN_SHARED_LIB}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi/
|
|
)
|
|
endif()
|
|
if (onnxruntime_USE_TVM)
|
|
add_custom_command(
|
|
TARGET onnxruntime_pybind11_state POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
$<TARGET_FILE:tvm> $<TARGET_FILE:nnvm_compiler>
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi/
|
|
)
|
|
endif()
|
|
|
|
if (onnxruntime_USE_MKLML)
|
|
add_custom_command(
|
|
TARGET onnxruntime_pybind11_state POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
${MKLML_LIB_DIR}/${MKLML_SHARED_LIB} ${MKLML_LIB_DIR}/${IOMP5MD_SHARED_LIB}
|
|
$<TARGET_FILE_DIR:${test_data_target}>/onnxruntime/capi/
|
|
)
|
|
endif()
|