From 4db10c93d131c8737bce4550676e8744d8a2d244 Mon Sep 17 00:00:00 2001 From: George Wu Date: Wed, 5 Apr 2023 07:53:29 -0700 Subject: [PATCH] [TensorRT EP] make --use_tensorrt_builtin_parser the default behavior in build.py (#15320) Change the default behavior to link against the nvonnxparser library (onnx-tensorrt parser) that is included with the TensorRT package. Previously, the default behavior was to build and statically link against the OSS onnx-tensorrt parser. Historically, we wanted to incorporate the latest commits/fixes from OSS parser. These days the OSS parser is not significantly different from the included parser library so there is less reason to build against it by default. By linking with parser shared library from TensorRT library, the major benefit is it's much easier to build/link against a minor version update of TensorRT. And OnnxRuntime can be updated with a new TensorRT minor version by simply replacing TensorRT libraries with the newer version. (because the parser is no longer statically linked into onnxruntime) Added --use_tensorrt_oss_parser to build.py to support the previous default behavior. (build + static link OSS parser) --- cmake/onnxruntime_providers.cmake | 4 +++- tools/ci_build/build.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 53508e64d0..39e00e2592 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -696,7 +696,9 @@ if (onnxruntime_USE_TENSORRT) endif() include_directories(${TENSORRT_INCLUDE_DIR}) - + # ${TENSORRT_LIBRARY} is empty if we link nvonnxparser_static. + # nvonnxparser_static is linked against tensorrt libraries in onnx-tensorrt + # See https://github.com/onnx/onnx-tensorrt/blob/8af13d1b106f58df1e98945a5e7c851ddb5f0791/CMakeLists.txt#L121 set(trt_link_libs cudnn cublas ${CMAKE_DL_LIBS} ${TENSORRT_LIBRARY}) file(GLOB_RECURSE onnxruntime_providers_tensorrt_cc_srcs CONFIGURE_DEPENDS diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 1e9681be0c..2a32a8bcf2 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -499,7 +499,10 @@ def parse_arguments(): "--use_tvm_hash", action="store_true", help="Build ipp-crypto for hash generation. It is used by TVM EP only" ) parser.add_argument("--use_tensorrt", action="store_true", help="Build with TensorRT") - parser.add_argument("--use_tensorrt_builtin_parser", action="store_true", help="Use TensorRT builtin parser") + parser.add_argument( + "--use_tensorrt_builtin_parser", action="store_true", default=True, help="Use TensorRT builtin parser" + ) + parser.add_argument("--use_tensorrt_oss_parser", action="store_true", help="Use TensorRT OSS parser") parser.add_argument( "--tensorrt_placeholder_builder", action="store_true", help="Instantiate Placeholder TensorRT Builder" ) @@ -916,7 +919,8 @@ def generate_build_tree( "-Donnxruntime_USE_TENSORRT=" + ("ON" if args.use_tensorrt else "OFF"), "-Donnxruntime_SKIP_AND_PERFORM_FILTERED_TENSORRT_TESTS=" + ("ON" if not args.tensorrt_placeholder_builder else "OFF"), - "-Donnxruntime_USE_TENSORRT_BUILTIN_PARSER=" + ("ON" if args.use_tensorrt_builtin_parser else "OFF"), + "-Donnxruntime_USE_TENSORRT_BUILTIN_PARSER=" + + ("ON" if args.use_tensorrt_builtin_parser and not args.use_tensorrt_oss_parser else "OFF"), "-Donnxruntime_TENSORRT_PLACEHOLDER_BUILDER=" + ("ON" if args.tensorrt_placeholder_builder else "OFF"), # set vars for TVM "-Donnxruntime_USE_TVM=" + ("ON" if args.use_tvm else "OFF"),