Skip to content

Commit 076a8af

Browse files
authored
fix C++ lint with clang-tidy, improve windows user experience (#1705)
1 parent e29066e commit 076a8af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1771
-1131
lines changed

.github/workflows/pre-commit.yml

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,40 @@ on:
66
- master
77
- trt10
88

9+
push:
10+
branches:
11+
- master
12+
- trt10
13+
914
jobs:
1015
pre-commit:
1116
runs-on: ubuntu-latest
17+
1218
steps:
13-
- uses: actions/checkout@v3
14-
with:
15-
# grab the history of the PR
16-
fetch-depth: 0
17-
- uses: actions/setup-python@v3
18-
- uses: pre-commit/action@v3.0.1
19-
with:
20-
extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
19+
- uses: actions/checkout@v5
20+
with:
21+
# grab the history of the PR
22+
fetch-depth: 0
23+
24+
- name: Fetch commits
25+
run: |
26+
git fetch origin ${{ github.event.before }} || true
27+
git fetch origin ${{ github.sha }}
28+
29+
- uses: actions/setup-python@v4
30+
31+
- uses: pre-commit/action@v3.0.1
32+
if: github.event_name == 'push'
33+
with:
34+
extra_args: >
35+
--from-ref ${{ github.event.before }}
36+
--to-ref ${{ github.sha }}
37+
--show-diff-on-failure --color=always
38+
39+
- uses: pre-commit/action@v3.0.1
40+
if: github.event_name == 'pull_request'
41+
with:
42+
extra_args: >
43+
--from-ref ${{ github.event.pull_request.base.sha }}
44+
--to-ref ${{ github.event.pull_request.head.sha }}
45+
--show-diff-on-failure --color=always

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ CMakeCache.txt
7070
CMakeFiles
7171
CMakeScripts
7272
Testing
73-
Makefile
7473
cmake_install.cmake
7574
install_manifest.txt
7675
compile_commands.json

.pre-commit-config.yaml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.5.0
44
hooks:
5-
- id: check-merge-conflict
5+
- id: check-merge-conflict
6+
- id: check-symlinks
7+
- id: end-of-file-fixer
68
types: [python]
7-
- id: check-symlinks
9+
- id: trailing-whitespace
810
types: [python]
9-
- id: end-of-file-fixer
10-
types: [python]
11-
- id: trailing-whitespace
12-
types: [python]
13-
- id: check-added-large-files
14-
types: [python]
15-
- repo: https://github.com/pre-commit/mirrors-clang-format
11+
- id: check-added-large-files
12+
- repo: https://github.com/pre-commit/mirrors-clang-format
1613
rev: v14.0.6
1714
hooks:
18-
- id: clang-format
15+
- id: clang-format
1916
types_or: [c++, c, cuda]
2017
args: [-style=file]
21-
- repo: https://github.com/PyCQA/flake8
18+
- repo: https://github.com/PyCQA/flake8
2219
rev: 7.0.0
2320
hooks:
24-
- id: flake8
21+
- id: flake8
2522
args: [--max-line-length=120]
26-
- repo: https://github.com/cheshirekow/cmake-format-precommit
27-
rev: v0.6.13
28-
hooks:
29-
- id: cmake-format
30-
additional_dependencies: [pyyaml]
31-
args: [--in-place, -c, .cmake-format.yaml]
32-
types: [file]
33-
files: (\.cmake|CMakeLists.txt)(.in)?$
23+
- repo: https://github.com/cheshirekow/cmake-format-precommit
24+
rev: v0.6.13
25+
hooks:
26+
- id: cmake-format
27+
additional_dependencies: [pyyaml]
28+
args: [--in-place, -c, .cmake-format.yaml]
29+
types: [file]
30+
files: (\.cmake|CMakeLists.txt)(.in)?$

alexnet/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ project(
77

88
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
99
set(CMAKE_CUDA_ARCHITECTURES
10-
60
11-
70
12-
72
1310
75
1411
80
1512
86
16-
89)
13+
89
14+
90
15+
100
16+
120)
1717
endif()
1818

1919
set(CMAKE_CXX_STANDARD 17)

alexnet/FindTensorRT.cmake

Lines changed: 71 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
cmake_minimum_required(VERSION 3.17.0)
22

3-
set(TRT_VERSION
4-
$ENV{TRT_VERSION}
5-
CACHE
6-
STRING
7-
"TensorRT version, e.g. \"8.6.1.6\" or \"8.6.1.6+cuda12.0.1.011\", etc")
8-
93
function(_guess_path var_name required_files)
104
set(_result "")
115

@@ -44,56 +38,84 @@ function(_guess_path var_name required_files)
4438
PARENT_SCOPE)
4539
endfunction()
4640

47-
# find TensorRT include folder
48-
if(NOT DEFINED TensorRT_INCLUDE_DIR)
49-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
50-
_guess_path(
51-
TensorRT_INCLUDE_DIR "NvInfer.h" "/usr/include/aarch64-linux-gnu"
52-
"/usr/include" "/usr/local/cuda/targets/aarch64-linux/include")
53-
else()
54-
_guess_path(
55-
TensorRT_INCLUDE_DIR "NvInfer.h"
56-
"/usr/local/tensorrt/targets/x86_64-linux-gnu/include"
57-
"/usr/include/x86_64-linux-gnu" "/usr/include")
58-
endif()
59-
message(STATUS "TensorRT includes: ${TensorRT_INCLUDE_DIR}")
41+
# add library
42+
add_library(TensorRT IMPORTED INTERFACE)
43+
add_library(TensorRT::TensorRT ALIAS TensorRT)
44+
45+
set(TRT_VERSION
46+
CACHE
47+
STRING
48+
"TensorRT version, e.g. \"8.6.1.6\" or \"8.6.1.6+cuda12.0.1.011\", \"8.6.1.6.Windows10.x86_64.cuda-12.0\" etc"
49+
)
50+
51+
if(NOT TRT_VERSION STREQUAL "" AND NOT $ENV{TRT_VERSION} STREQUAL "")
52+
message(
53+
WARNING
54+
"TRT_VERSION defined by cmake and environment variable both, using the later one"
55+
)
6056
endif()
6157

62-
# find TensorRT library folder
63-
if(NOT TensorRT_LIBRARY_DIR)
64-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
65-
_guess_path(
66-
TensorRT_LIBRARY_DIR "libnvinfer.so;libnvinfer_plugin.so"
67-
"/usr/lib/aarch64-linux-gnu;/usr/lib/aarch64-linux-gnu/tegra" "/usr/lib")
68-
else()
69-
_guess_path(
70-
TensorRT_LIBRARY_DIR
71-
"libnvinfer.so;libnvinfer_plugin.so"
72-
"/usr/lib/x86_64-linux-gnu;/usr/local/tensorrt/targets/x86_64-linux-gnu/lib;/usr/lib"
58+
if(NOT $ENV{TRT_VERSION} STREQUAL "")
59+
set(TRT_VERSION $ENV{TRT_VERSION})
60+
endif()
61+
62+
string(REGEX MATCH "([0-9]+)" _match ${TRT_VERSION})
63+
set(TRT_MAJOR_VERSION "${_match}")
64+
unset(_match)
65+
66+
if(WIN32)
67+
set(TensorRT_DIR "C:/Program Files/TensorRT-${TRT_VERSION}")
68+
if(NOT EXISTS "${TensorRT_DIR}")
69+
message(
70+
FATAL_ERROR
71+
"TensorRT_DIR=${TensorRT_DIR} does not exist!"
7372
)
7473
endif()
75-
message(STATUS "TensorRT libraries: ${TensorRT_LIBRARY_DIR}")
76-
endif()
7774

78-
set(TensorRT_LIBRARIES)
75+
if(${TRT_MAJOR_VERSION} GREATER_EQUAL 10)
76+
set(_modules nvinfer_10 nvinfer_plugin_10 nvinfer_vc_plugin_10
77+
nvinfer_dispatch_10 nvinfer_lean_10)
78+
message(DEBUG "Using ${_modules}")
79+
else()
80+
set(_modules nvinfer nvinfer_plugin nvinfer_vc_plugin nvinfer_dispatch
81+
nvinfer_lean)
82+
endif()
7983

80-
message(STATUS "Found TensorRT lib: ${TensorRT_LIBRARIES}")
84+
set(TensorRT_LIBRARY_DIR "${TensorRT_DIR}/lib")
85+
set(TensorRT_INCLUDE_DIR "${TensorRT_DIR}/include")
86+
elseif(UNIX)
87+
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _trt_arch)
88+
set(_trt_include_candidates)
89+
if(_trt_arch MATCHES "^(aarch64|arm64|arch64)$")
90+
set(_trt_include_candidates "/usr/include/aarch64-linux-gnu" "/usr/include"
91+
"/usr/local/cuda/targets/aarch64-linux/include")
92+
set(_trt_library_candidates
93+
"/usr/local/tensorrt/targets/aarch64-linux-gnu/lib"
94+
"/usr/lib/aarch64-linux-gnu" "/usr/lib/aarch64-linux-gnu/tegra"
95+
"/usr/lib")
96+
elseif(_trt_arch MATCHES "^(x86_64|amd64)$")
97+
set(_trt_include_candidates
98+
"/usr/local/tensorrt/targets/x86_64-linux-gnu/include"
99+
"/usr/include/x86_64-linux-gnu" "/usr/include")
100+
set(_trt_library_candidates
101+
"/usr/local/tensorrt/targets/x86_64-linux-gnu/lib"
102+
"/usr/lib/x86_64-linux-gnu" "/usr/lib")
103+
else()
104+
message(FATAL_ERROR "Unknown architecture")
105+
endif()
81106

82-
# process for different TensorRT version
83-
if(DEFINED TRT_VERSION AND NOT TRT_VERSION STREQUAL "")
84-
string(REGEX MATCH "([0-9]+)" _match ${TRT_VERSION})
85-
set(TRT_MAJOR_VERSION "${_match}")
86107
set(_modules nvinfer nvinfer_plugin)
87-
unset(_match)
88-
89-
if(TRT_MAJOR_VERSION GREATER_EQUAL 8)
108+
if(${TRT_MAJOR_VERSION} GREATER_EQUAL 8)
90109
list(APPEND _modules nvinfer_vc_plugin nvinfer_dispatch nvinfer_lean)
91110
endif()
92-
else()
93-
message(FATAL_ERROR "Please set a environment variable \"TRT_VERSION\"")
111+
112+
_guess_path(TensorRT_LIBRARY_DIR "libnvinfer.so;libnvinfer_plugin.so"
113+
${_trt_library_candidates})
114+
message(STATUS "TensorRT libraries: ${TensorRT_LIBRARY_DIR}")
115+
_guess_path(TensorRT_INCLUDE_DIR "NvInfer.h" ${_trt_include_candidates})
116+
message(STATUS "TensorRT includes: ${TensorRT_INCLUDE_DIR}")
94117
endif()
95118

96-
# find and add all modules of TensorRT into list
97119
foreach(lib IN LISTS _modules)
98120
find_library(
99121
TensorRT_${lib}_LIBRARY
@@ -102,11 +124,10 @@ foreach(lib IN LISTS _modules)
102124
list(APPEND TensorRT_LIBRARIES ${TensorRT_${lib}_LIBRARY})
103125
endforeach()
104126

105-
# make the "TensorRT target"
106-
add_library(TensorRT IMPORTED INTERFACE)
107-
add_library(TensorRT::TensorRT ALIAS TensorRT)
108127
target_link_libraries(TensorRT INTERFACE ${TensorRT_LIBRARIES})
109128

129+
message(STATUS "Found TensorRT libs: ${TensorRT_LIBRARIES}")
130+
110131
set_target_properties(
111132
TensorRT
112133
PROPERTIES C_STANDARD 17
@@ -119,3 +140,6 @@ set_target_properties(
119140

120141
unset(TRT_MAJOR_VERSION)
121142
unset(_modules)
143+
unset(_trt_include_candidates)
144+
unset(_trt_library_candidates)
145+
unset(_trt_arch)

0 commit comments

Comments
 (0)