Skip to content

Commit

Permalink
[BYOC][TensorRT] TensorRT BYOC integration (#6395)
Browse files Browse the repository at this point in the history
* TensorRT integration using JSONRuntime

Support input nodes with multiple data entries

Fix failing tests

Support layout transform, add engine caching

Add comment

Add PruneSubgraph pass

Use prune_subgraph pass, make params member of trt runtime class

Hide deprecation warnings coming from TRT headers

Remove general prune subgraph

Save/load use_implicit_batch and workspace size

Clean up

Fix cpp lint

Addressing review comments

Refactor tests

Use relay.bind instead of VarReplacer. Improve some annotation functions

Add TRT docs

Use DLOG, formatting

Use logging.info instead of print

also  refactor integ tests

also  refactor integ tests

Formatting

Formatting

Format python

fix python format

Fix pylint

Fix sphinx precheck

Add tensorrt.rst to toctree

Allow codegen to be tested when TRT runtime is not available. Enable TRT codegen in CI

linty

Address more comments

Formatting

Formatting

* Documentation changes

* Address comments

* Rename USE_TENSORRT->USE_TENSORRT_CODEGEN and USE_TENSORRT_GRAPH_RUNTIME->USE_TENSORRT_RUNTIME

* Fix comment typo

* Test CI without TRT codegen enabled

* formatting

* Enable USE_TENSORRT_CODEGEN in CI

* Change file_util.h -> file_utils.h
  • Loading branch information
Trevor Morris authored Oct 19, 2020
1 parent 28e9ab7 commit af8636a
Show file tree
Hide file tree
Showing 17 changed files with 4,403 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ tvm_option(USE_COREML "Build with coreml support" OFF)
tvm_option(USE_TARGET_ONNX "Build with ONNX Codegen support" OFF)
tvm_option(USE_ARM_COMPUTE_LIB "Build with Arm Compute Library" OFF)
tvm_option(USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME "Build with Arm Compute Library graph runtime" OFF)
tvm_option(USE_TENSORRT_CODEGEN "Build with TensorRT Codegen support" OFF)
tvm_option(USE_TENSORRT_RUNTIME "Build with TensorRT runtime" OFF)

# include directories
include_directories(${CMAKE_INCLUDE_PATH})
Expand Down Expand Up @@ -347,6 +349,7 @@ include(cmake/modules/contrib/TF_TVMDSOOP.cmake)
include(cmake/modules/contrib/CoreML.cmake)
include(cmake/modules/contrib/ONNX.cmake)
include(cmake/modules/contrib/ArmComputeLib.cmake)
include(cmake/modules/contrib/TensorRT.cmake)
include(cmake/modules/Git.cmake)
include(cmake/modules/LibInfo.cmake)

Expand Down
10 changes: 10 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ set(USE_ETHOSN OFF)
# otherwise use ETHOSN_HW (OFF) to use the software test infrastructure
set(USE_ETHOSN_HW OFF)

# Whether to build with TensorRT codegen or runtime
# Examples are available here: docs/deploy/tensorrt.rst.
#
# USE_TENSORRT_CODEGEN - Support for compiling a relay graph where supported operators are
# offloaded to TensorRT. OFF/ON
# USE_TENSORRT_RUNTIME - Support for running TensorRT compiled modules, requires presense of
# TensorRT library. OFF/ON/"path/to/TensorRT"
set(USE_TENSORRT_CODEGEN OFF)
set(USE_TENSORRT_RUNTIME OFF)

# Build ANTLR parser for Relay text format
# Possible values:
# - ON: enable ANTLR by searching default locations (cmake find_program for antlr4 and /usr/local for jar)
Expand Down
54 changes: 54 additions & 0 deletions cmake/modules/contrib/TensorRT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# TensorRT Codegen only. This can be enabled independently of USE_TENSORRT_RUNTIME to enable
# compilation of TensorRT modules without requiring TensorRT to be installed. The compiled modules
# will only be able to be executed using a TVM built with USE_TENSORRT_RUNTIME=ON.
if(USE_TENSORRT_CODEGEN)
message(STATUS "Build with TensorRT codegen")
file(GLOB COMPILER_TENSORRT_SRCS src/relay/backend/contrib/tensorrt/*.cc)
set_source_files_properties(${COMPILER_TENSORRT_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
file(GLOB RUNTIME_TENSORRT_SRCS src/runtime/contrib/tensorrt/tensorrt_runtime.cc)
set_source_files_properties(${RUNTIME_TENSORRT_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
list(APPEND COMPILER_SRCS ${COMPILER_TENSORRT_SRCS})
list(APPEND COMPILER_SRCS ${RUNTIME_TENSORRT_SRCS})
endif()

# TensorRT Runtime
if(USE_TENSORRT_RUNTIME)
if(IS_DIRECTORY ${USE_TENSORRT_RUNTIME})
set(TENSORRT_ROOT_DIR ${USE_TENSORRT_RUNTIME})
message(STATUS "Custom TensorRT path: " ${TENSORRT_ROOT_DIR})
endif()
find_path(TENSORRT_INCLUDE_DIR NvInfer.h HINTS ${TENSORRT_ROOT_DIR} PATH_SUFFIXES include)
find_library(TENSORRT_LIB_DIR nvinfer HINTS ${TENSORRT_ROOT_DIR} PATH_SUFFIXES lib)
find_package_handle_standard_args(TENSORRT DEFAULT_MSG TENSORRT_INCLUDE_DIR TENSORRT_LIB_DIR)
if(NOT TENSORRT_FOUND)
message(ERROR "Could not find TensorRT.")
endif()
message(STATUS "TENSORRT_LIB_DIR: " ${TENSORRT_LIB_DIR})
include_directories(${TENSORRT_INCLUDE_DIR})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${TENSORRT_LIB_DIR})

# TRT runtime sources
file(GLOB RUNTIME_TENSORRT_SRCS src/runtime/contrib/tensorrt/*.cc)
set_source_files_properties(${RUNTIME_TENSORRT_SRCS} PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations")
list(APPEND RUNTIME_SRCS ${RUNTIME_TENSORRT_SRCS})

# Set defines
add_definitions(-DTVM_GRAPH_RUNTIME_TENSORRT)
endif()
1 change: 1 addition & 0 deletions docs/deploy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ target device without relying on RPC. see the following resources on how to do s
integrate
hls
arm_compute_lib
tensorrt
Loading

0 comments on commit af8636a

Please sign in to comment.