-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] 2 basic demos and all related documents
- Loading branch information
Showing
31 changed files
with
1,213 additions
and
958 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project( | ||
tensorrtx | ||
VERSION 0.1 | ||
LANGUAGES C CXX CUDA) | ||
|
||
set(TensorRT_7_8_10_TARGETS mlp lenet) | ||
|
||
set(TensorRT_8_TARGETS) | ||
|
||
set(TensorRT_10_TARGETS) | ||
|
||
set(ALL_TARGETS ${TensorRT_7_8_10_TARGETS} ${TensorRT_8_TARGETS} | ||
${TensorRT_10_TARGETS}) | ||
|
||
foreach(sub_dir ${ALL_TARGETS}) | ||
message(STATUS "Add subdirectory: ${sub_dir}") | ||
add_subdirectory(${sub_dir}) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
|
||
project(lenet) | ||
|
||
add_definitions(-std=c++11) | ||
|
||
set(TARGET_NAME "lenet") | ||
|
||
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF) | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_BUILD_TYPE Debug) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/include) | ||
# include and link dirs of cuda and tensorrt, you need adapt them if yours are different | ||
# cuda | ||
include_directories(/usr/local/cuda/include) | ||
link_directories(/usr/local/cuda/lib64) | ||
# tensorrt | ||
include_directories(/usr/include/x86_64-linux-gnu/) | ||
link_directories(/usr/lib/x86_64-linux-gnu/) | ||
|
||
FILE(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/lenet.cpp ${PROJECT_SOURCE_DIR}/include/*.h) | ||
|
||
add_executable(${TARGET_NAME} ${SRC_FILES}) | ||
target_link_libraries(${TARGET_NAME} nvinfer) | ||
target_link_libraries(${TARGET_NAME} cudart) | ||
|
||
add_definitions(-O2 -pthread) | ||
|
||
cmake_minimum_required(VERSION 3.17.0) | ||
|
||
project( | ||
lenet | ||
VERSION 0.1 | ||
LANGUAGES C CXX CUDA) | ||
|
||
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) | ||
set(CMAKE_CUDA_ARCHITECTURES | ||
60 | ||
70 | ||
72 | ||
75 | ||
80 | ||
86 | ||
89) | ||
endif() | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CUDA_STANDARD 17) | ||
set(CMAKE_CUDA_STANDARD_REQUIRED ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_INCLUDE_CURRENT_DIR TRUE) | ||
set(CMAKE_BUILD_TYPE | ||
"Debug" | ||
CACHE STRING "Build type for this project" FORCE) | ||
|
||
option(CUDA_USE_STATIC_CUDA_RUNTIME "Use static cudaruntime library" OFF) | ||
|
||
find_package(Threads REQUIRED) | ||
find_package(CUDAToolkit REQUIRED) | ||
|
||
if(NOT TARGET TensorRT::TensorRT) | ||
include(FindTensorRT.cmake) | ||
else() | ||
message("TensorRT has been found, skipping for ${PROJECT_NAME}") | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} lenet.cpp) | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads CUDA::cudart | ||
TensorRT::TensorRT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
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\"") | ||
|
||
# find TensorRT include folder | ||
if(NOT TensorRT_INCLUDE_DIR) | ||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") | ||
set(TensorRT_INCLUDE_DIR | ||
"/usr/local/cuda/targets/aarch64-linux/include" | ||
CACHE PATH "TensorRT_INCLUDE_DIR") | ||
else() | ||
set(TensorRT_INCLUDE_DIR | ||
"/usr/include/x86_64-linux-gnu" | ||
CACHE PATH "TensorRT_INCLUDE_DIR") | ||
endif() | ||
message(STATUS "TensorRT: ${TensorRT_INCLUDE_DIR}") | ||
endif() | ||
|
||
# find TensorRT library folder | ||
if(NOT TensorRT_LIBRARY_DIR) | ||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") | ||
set(TensorRT_LIBRARY_DIR | ||
"/usr/lib/aarch64-linux-gnu/tegra" | ||
CACHE PATH "TensorRT_LIBRARY_DIR") | ||
else() | ||
set(TensorRT_LIBRARY_DIR | ||
"/usr/include/x86_64-linux-gnu" | ||
CACHE PATH "TensorRT_LIBRARY_DIR") | ||
endif() | ||
message(STATUS "TensorRT: ${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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.