tensorrt 官方下载地址(需要注册账号登录):Log in | NVIDIA Developer
根据系统发行版和CUDA版本 (nvcc -V) 选择合适的安装包
EA(early access)版本代表抢先体验。
GA(general availability)代表稳定版,经过全面测试。
建议选用 TensorRT 最新版本的 GA release
为了不影响系统环境,只进行单个 C++ 项目的开发,这里选用 TAR Package,解压即用,无需安装。
tar -zxvf TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-11.8.tar.gz
cmake 文件参考
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CUDA_ARCHITECTURES 60 61 62 70 72 75 86)
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
project(yolov8 LANGUAGES CXX CUDA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE Release)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
# CUDA
find_package(CUDA REQUIRED)
message(STATUS "CUDA Libs: \n${CUDA_LIBRARIES}\n")
get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
message(STATUS "CUDA Headers: \n${CUDA_INCLUDE_DIRS}\n")
# OpenCV
set(OpenCV_DIR "/home/c++/lib/opencv-4.8.1/build")
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV Libs: \n${OpenCV_LIBS}\n")
message(STATUS "OpenCV Libraries: \n${OpenCV_LIBRARIES}\n")
message(STATUS "OpenCV Headers: \n${OpenCV_INCLUDE_DIRS}\n")
# TensorRT
set(TensorRT_INCLUDE_DIRS "/home/c++/lib/TensorRT-8.6.1.6/include")
set(TensorRT_LIBRARIES "/home/c++/lib/TensorRT-8.6.1.6/lib")
set(TensorRT_LIB1 "/home/c++/lib/TensorRT-8.6.1.6/lib/libnvinfer.so")
set(TensorRT_LIB2 "/home/c++/lib/TensorRT-8.6.1.6/lib/libnvinfer_plugin.so")
message(STATUS "TensorRT Libs: \n${TensorRT_LIBRARIES}\n")
message(STATUS "TensorRT Headers: \n${TensorRT_INCLUDE_DIRS}\n")
list(APPEND INCLUDE_DIRS
${CUDA_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${TensorRT_INCLUDE_DIRS}
include
)
list(APPEND ALL_LIBS
${CUDA_LIBRARIES}
${CUDA_LIB_DIR}
${OpenCV_LIBRARIES}
${TensorRT_LIBRARIES}
)
include_directories(${INCLUDE_DIRS})
add_executable(${PROJECT_NAME}
main.cpp
include/yolov8.hpp
include/common.hpp
)
link_directories(${ALL_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CUDA_LIBRARIES} ${OpenCV_LIBS} ${TensorRT_LIB1} ${TensorRT_LIB2})