Skip to content

Commit c5ca891

Browse files
authored
Download TensorRT python header if it's not found (#1015)
Signed-off-by: Kevin Chen <[email protected]>
1 parent c97b5b0 commit c5ca891

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,30 @@ MESSAGE(STATUS "Found TensorRT headers at ${TENSORRT_INCLUDE_DIR}")
110110
find_path(TENSORRT_PYTHON_INCLUDE_DIR plugin.h
111111
HINTS ${TENSORRT_ROOT}
112112
PATH_SUFFIXES python/include/impl)
113+
114+
# If header is not found, download it from open source release.
115+
if(NOT TENSORRT_PYTHON_INCLUDE_DIR)
116+
set(PLUGIN_URL "https://raw.githubusercontent.com/NVIDIA/TensorRT/refs/heads/release/${ONNX2TRT_MAJOR}.${ONNX2TRT_MINOR}/python/include/impl/plugin.h")
117+
set(FILE_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/plugin.h")
118+
119+
message(NOTICE "Required header plugin.h not found. Downloading from ${PLUGIN_URL} to ${FILE_DESTINATION}")
120+
121+
file(DOWNLOAD ${PLUGIN_URL} ${FILE_DESTINATION}
122+
SHOW_PROGRESS
123+
STATUS DOWNLOAD_STATUS
124+
LOG DOWNLOAD_LOG
125+
)
126+
127+
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
128+
list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE)
129+
130+
if(NOT STATUS_CODE EQUAL 0)
131+
message(FATAL_ERROR "Error downloading file: ${ERROR_MESSAGE}")
132+
endif()
133+
134+
set(TENSORRT_PYTHON_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
135+
endif()
136+
113137
message(NOTICE "Found TensorRT Python headers at ${TENSORRT_PYTHON_INCLUDE_DIR}")
114138

115139
# Output dynamic library names depends on platform:

0 commit comments

Comments
 (0)