Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,40 @@ on:
- master
- trt10

push:
branches:
- master
- trt10

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
# grab the history of the PR
fetch-depth: 0
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
with:
extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v5
with:
# grab the history of the PR
fetch-depth: 0

- name: Fetch commits
run: |
git fetch origin ${{ github.event.before }} || true
git fetch origin ${{ github.sha }}

- uses: actions/setup-python@v4

- uses: pre-commit/action@v3.0.1
if: github.event_name == 'push'
with:
extra_args: >
--from-ref ${{ github.event.before }}
--to-ref ${{ github.sha }}
--show-diff-on-failure --color=always

- uses: pre-commit/action@v3.0.1
if: github.event_name == 'pull_request'
with:
extra_args: >
--from-ref ${{ github.event.pull_request.base.sha }}
--to-ref ${{ github.event.pull_request.head.sha }}
--show-diff-on-failure --color=always
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
Expand Down
39 changes: 18 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-merge-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: end-of-file-fixer
types: [python]
- id: check-symlinks
- id: trailing-whitespace
types: [python]
- id: end-of-file-fixer
types: [python]
- id: trailing-whitespace
types: [python]
- id: check-added-large-files
types: [python]
- repo: https://github.com/pre-commit/mirrors-clang-format
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
- id: clang-format
types_or: [c++, c, cuda]
args: [-style=file]
- repo: https://github.com/PyCQA/flake8
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- id: flake8
args: [--max-line-length=120]
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
args: [--in-place, -c, .cmake-format.yaml]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
args: [--in-place, -c, .cmake-format.yaml]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$
8 changes: 4 additions & 4 deletions alexnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ project(

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES
60
70
72
75
80
86
89)
89
90
100
120)
endif()

set(CMAKE_CXX_STANDARD 17)
Expand Down
118 changes: 71 additions & 47 deletions alexnet/FindTensorRT.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
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 "")

Expand Down Expand Up @@ -44,56 +38,84 @@ function(_guess_path var_name required_files)
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}")
# add library
add_library(TensorRT IMPORTED INTERFACE)
add_library(TensorRT::TensorRT ALIAS TensorRT)

set(TRT_VERSION
CACHE
STRING
"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"
)

if(NOT TRT_VERSION STREQUAL "" AND NOT $ENV{TRT_VERSION} STREQUAL "")
message(
WARNING
"TRT_VERSION defined by cmake and environment variable both, using the later one"
)
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"
if(NOT $ENV{TRT_VERSION} STREQUAL "")
set(TRT_VERSION $ENV{TRT_VERSION})
endif()

string(REGEX MATCH "([0-9]+)" _match ${TRT_VERSION})
set(TRT_MAJOR_VERSION "${_match}")
unset(_match)

if(WIN32)
set(TensorRT_DIR "C:/Program Files/TensorRT-${TRT_VERSION}")
if(NOT EXISTS "${TensorRT_DIR}")
message(
FATAL_ERROR
"TensorRT_DIR=${TensorRT_DIR} does not exist!"
)
endif()
message(STATUS "TensorRT libraries: ${TensorRT_LIBRARY_DIR}")
endif()

set(TensorRT_LIBRARIES)
if(${TRT_MAJOR_VERSION} GREATER_EQUAL 10)
set(_modules nvinfer_10 nvinfer_plugin_10 nvinfer_vc_plugin_10
nvinfer_dispatch_10 nvinfer_lean_10)
message(DEBUG "Using ${_modules}")
else()
set(_modules nvinfer nvinfer_plugin nvinfer_vc_plugin nvinfer_dispatch
nvinfer_lean)
endif()

message(STATUS "Found TensorRT lib: ${TensorRT_LIBRARIES}")
set(TensorRT_LIBRARY_DIR "${TensorRT_DIR}/lib")
set(TensorRT_INCLUDE_DIR "${TensorRT_DIR}/include")
elseif(UNIX)
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _trt_arch)
set(_trt_include_candidates)
if(_trt_arch MATCHES "^(aarch64|arm64|arch64)$")
set(_trt_include_candidates "/usr/include/aarch64-linux-gnu" "/usr/include"
"/usr/local/cuda/targets/aarch64-linux/include")
set(_trt_library_candidates
"/usr/local/tensorrt/targets/aarch64-linux-gnu/lib"
"/usr/lib/aarch64-linux-gnu" "/usr/lib/aarch64-linux-gnu/tegra"
"/usr/lib")
elseif(_trt_arch MATCHES "^(x86_64|amd64)$")
set(_trt_include_candidates
"/usr/local/tensorrt/targets/x86_64-linux-gnu/include"
"/usr/include/x86_64-linux-gnu" "/usr/include")
set(_trt_library_candidates
"/usr/local/tensorrt/targets/x86_64-linux-gnu/lib"
"/usr/lib/x86_64-linux-gnu" "/usr/lib")
else()
message(FATAL_ERROR "Unknown architecture")
endif()

# 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)
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\"")

_guess_path(TensorRT_LIBRARY_DIR "libnvinfer.so;libnvinfer_plugin.so"
${_trt_library_candidates})
message(STATUS "TensorRT libraries: ${TensorRT_LIBRARY_DIR}")
_guess_path(TensorRT_INCLUDE_DIR "NvInfer.h" ${_trt_include_candidates})
message(STATUS "TensorRT includes: ${TensorRT_INCLUDE_DIR}")
endif()

# find and add all modules of TensorRT into list
foreach(lib IN LISTS _modules)
find_library(
TensorRT_${lib}_LIBRARY
Expand All @@ -102,11 +124,10 @@ foreach(lib IN LISTS _modules)
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})

message(STATUS "Found TensorRT libs: ${TensorRT_LIBRARIES}")

set_target_properties(
TensorRT
PROPERTIES C_STANDARD 17
Expand All @@ -119,3 +140,6 @@ set_target_properties(

unset(TRT_MAJOR_VERSION)
unset(_modules)
unset(_trt_include_candidates)
unset(_trt_library_candidates)
unset(_trt_arch)
Loading
Loading