-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathFindTensorRT.cmake
More file actions
121 lines (104 loc) · 3.46 KB
/
FindTensorRT.cmake
File metadata and controls
121 lines (104 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
cmake_minimum_required(VERSION 3.17.0)
set(TRT_VERSION
$ENV{TRT_VERSION}
CACHE
STRING
"TensorRT version, e.g. \"8.6.1.6\" or \"8.6.1.6+cuda12.0.1.011\", etc")
function(_guess_path var_name required_files)
set(_result "")
foreach(path_entry IN LISTS ARGN)
if(NOT EXISTS "${path_entry}")
message(DEBUG "skip non-existing path '${path_entry}'")
continue()
endif()
set(_ok TRUE)
foreach(required_file IN LISTS required_files)
if(NOT EXISTS "${path_entry}/${required_file}")
set(_ok FALSE)
message(DEBUG "'${path_entry}' missing '${required_file}'")
break()
endif()
endforeach()
if(_ok)
list(APPEND _result "${path_entry}")
message(DEBUG "accept '${path_entry}'")
else()
message(DEBUG "reject '${path_entry}'")
endif()
endforeach()
if(_result STREQUAL "")
message(
FATAL_ERROR
"_guess_path(${var_name}) failed: no valid path found. required_files='${required_files}' candidates='${ARGN}'"
)
endif()
set(${var_name}
"${_result}"
PARENT_SCOPE)
endfunction()
# find TensorRT include folder
if(NOT DEFINED TensorRT_INCLUDE_DIR)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
_guess_path(
TensorRT_INCLUDE_DIR "NvInfer.h" "/usr/include/aarch64-linux-gnu"
"/usr/include" "/usr/local/cuda/targets/aarch64-linux/include")
else()
_guess_path(
TensorRT_INCLUDE_DIR "NvInfer.h"
"/usr/local/tensorrt/targets/x86_64-linux-gnu/include"
"/usr/include/x86_64-linux-gnu" "/usr/include")
endif()
message(STATUS "TensorRT includes: ${TensorRT_INCLUDE_DIR}")
endif()
# find TensorRT library folder
if(NOT TensorRT_LIBRARY_DIR)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
_guess_path(
TensorRT_LIBRARY_DIR "libnvinfer.so;libnvinfer_plugin.so"
"/usr/lib/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu/tegra" "/usr/lib")
else()
_guess_path(
TensorRT_LIBRARY_DIR
"libnvinfer.so;libnvinfer_plugin.so"
"/usr/lib/x86_64-linux-gnu;/usr/local/tensorrt/targets/x86_64-linux-gnu/lib;/usr/lib"
)
endif()
message(STATUS "TensorRT libraries: ${TensorRT_LIBRARY_DIR}")
endif()
set(TensorRT_LIBRARIES)
message(STATUS "Found TensorRT lib: ${TensorRT_LIBRARIES}")
# process for different TensorRT version
if(DEFINED TRT_VERSION AND NOT TRT_VERSION STREQUAL "")
string(REGEX MATCH "([0-9]+)" _match ${TRT_VERSION})
set(TRT_MAJOR_VERSION "${_match}")
set(_modules nvinfer nvinfer_plugin)
unset(_match)
if(TRT_MAJOR_VERSION GREATER_EQUAL 8)
list(APPEND _modules nvinfer_vc_plugin nvinfer_dispatch nvinfer_lean)
endif()
else()
message(FATAL_ERROR "Please set a environment variable \"TRT_VERSION\"")
endif()
# find and add all modules of TensorRT into list
foreach(lib IN LISTS _modules)
find_library(
TensorRT_${lib}_LIBRARY
NAMES ${lib}
HINTS ${TensorRT_LIBRARY_DIR})
list(APPEND TensorRT_LIBRARIES ${TensorRT_${lib}_LIBRARY})
endforeach()
# make the "TensorRT target"
add_library(TensorRT IMPORTED INTERFACE)
add_library(TensorRT::TensorRT ALIAS TensorRT)
target_link_libraries(TensorRT INTERFACE ${TensorRT_LIBRARIES})
set_target_properties(
TensorRT
PROPERTIES C_STANDARD 17
CXX_STANDARD 17
POSITION_INDEPENDENT_CODE ON
SKIP_BUILD_RPATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN"
INTERFACE_INCLUDE_DIRECTORIES "${TensorRT_INCLUDE_DIR}")
unset(TRT_MAJOR_VERSION)
unset(_modules)