apollo 编译
makefile
apollo源无法安装libxml2_dev所以添加一些源
sudo vi /etc/apt/sources.list
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
install libxml
apollo 已经有opencv和libxml2,所以只需要安装libxml2-dev
$ apt update
$ apt install libxml2-dev
$ cp -r /usr/include/libxml2/libxml /usr/include/
1. cd TensorRT7.2/
2. mkdir build
3. cd build/
4. cmake -DPARAM_PATH="/nisi/Projects/apollo/modules/omnisense/preception/tiny-tensorrt7.2/test.xml" ..
5. make -j12
6. echo "export LD_LIBRARY_PATH={/TensorRT7.2/build/}:$LD_LIBRARY_PATH" >> ~/.bashrc
7. source ~/.bashrc
8. cd tiny-tensorrt7.2/
9. mkdir build
10. cd build
11. cmake ..
12. make -j8
13. CUDA_VISIBLE_DEVICES=2 ./unit_test --onnx_path ../../centerpoint_inno_luduan_sepHead_whole_large_model.onnx --data_path ../testbin/
Cmake 编译
学习资料
学习笔记
- 加头文件目录 include_directories(…/…/…/thirdparty/comm/include)
- 连接库文件目录 link_directories(“/home/server/third/lib”)
- 链接库文件目录 link_libraries(“/opt/MATLAB/R2012a/bin/glnxa64/libeng.so”)
- 链接库文件名称 target_link_libraries(myProject comm)
- 查找库所在目录 FIND_LIBRARY(RUNTIME_LIB rt /usr/lib /usr/local/lib NO_DEFAULT_PATH)
- 生成目标文件 add_executable(demo main.cpp) or add_executable(demo ${SOURCE_FILES})
生成动态库:
add_library(libsugan ${SRC_LISTS})
target_link_libraries(libsugan
${OpenCV_LIBS}
${PROJECT_SOURCE_DIR}/lib/libCommonUtilities.so
)
链接第三方库
find_package(OpenCV REQUIRED)
include_directories(${OPENCV_INCLUDE_DIRS})
target_link_libraries(demo ${OpenCV_LIBS})
动态弘
通过执行的时候设置release/debug来控制
在代码里设置bebug模式:
#IFDEF DEBUG
some print command;
#ENDIF
$ cmake -DCMAKE_BUILD_TYPE=Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
list
增加删除项等
if (DEFINED GPU_ARCHS)
message(STATUS "GPU_ARCHS defined as ${GPU_ARCHS}. Generating CUDA code for SM ${GPU_ARCHS}")
separate_arguments(GPU_ARCHS)
else()
list(APPEND GPU_ARCHS
70
72
75
)
string(REGEX MATCH "aarch64" IS_ARM "${TRT_PLATFORM_ID}")
if (IS_ARM)
# Xavier (SM72) only supported for aarch64.
list(APPEND GPU_ARCHS 72)
endif()
install rules
在CMake中,安装是指将二进制文件、库文件和头文件等安装到指定目录中。
install(TARGETS targets... [EXPORT <export-name>]
[[ARCHIVE|LIBRARY|RUNTIME|OBJECTS|FRAMEWORK|BUNDLE|
PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]
[DESTINATION <dir>]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
[NAMELINK_COMPONENT <component>]
[OPTIONAL] [EXCLUDE_FROM_ALL]
[NAMELINK_ONLY|NAMELINK_SKIP]
] [...]
[INCLUDES DESTINATION [<dir> ...]]
)
- DESTINATION:指定要安装到的目录,如果是相对路径,则是相对于CMAKE_INSTALL_PREFIX变量的,如果是绝对路径,则直接使用,由于cpack的安装程序生成器不支持绝对路径,所有最好使用相对路径
- PERMISSIONS: 指定安装文件的权限
- CONFIGURATIONS: 指定安装规则适用的构建配置(Debug, Relase等)
- EXCLUDE_FROM_ALL: 指定该文件从完整安装中排除。
- ARCHIVE: 静态库, LIBRARY: 动态库, RUNTIME: 可执行文件
当通过命令行使用cmake --install .或者make install时,将会运行安装步骤。如果要指定安装的根目录,需要使用cmake --install --prefix “/home/user/installdir” .来指定
example
#声明要求的cmake最低版本
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
include(cmake/modules/set_ifndef.cmake)
include(cmake/modules/find_library_create_target.cmake)
set_ifndef(TRT_LIB_DIR ${CMAKE_BINARY_DIR})
set_ifndef(TRT_OUT_DIR ${CMAKE_BINARY_DIR})
# 添加c++ 14标准支持
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS FALSE)
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/NvInferVersion.h" VERSION_STRINGS REGEX "#define NV_TENSORRT_.*")
foreach(TYPE MAJOR MINOR PATCH BUILD)
string(REGEX MATCH "NV_TENSORRT_${TYPE} [0-9]" TRT_TYPE_STRING ${VERSION_STRINGS})
string(REGEX MATCH "[0-9]" TRT_${TYPE} ${TRT_TYPE_STRING})
endforeach(TYPE)
foreach(TYPE MAJOR MINOR PATCH)
string(REGEX MATCH "NV_TENSORRT_SONAME_${TYPE} [0-9]" TRT_TYPE_STRING ${VERSION_STRINGS})
string(REGEX MATCH "[0-9]" TRT_SO_${TYPE} ${TRT_TYPE_STRING})
endforeach(TYPE)
set(TRT_VERSION "${TRT_MAJOR}.${TRT_MINOR}.${TRT_PATCH}" CACHE STRING "TensorRT project version")
set(TRT_SOVERSION "${TRT_SO_MAJOR}" CACHE STRING "TensorRT library so version")
message("Building for TensorRT version: ${TRT_VERSION}, library version: ${TRT_SOVERSION}")
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++)
endif()
set(CMAKE_SKIP_BUILD_RPATH True)
project(TensorRT
LANGUAGES CXX CUDA
VERSION ${TRT_VERSION}
DESCRIPTION "TensorRT is a C++ library that facilitates high performance inference on NVIDIA GPUs and deep learning accelerators."
HOMEPAGE_URL "https://github.com/NVIDIA/TensorRT")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${TRT_LIB_DIR}/../ CACHE PATH "TensorRT installation" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
option(BUILD_PLUGINS "Build TensorRT plugin" ON)
option(BUILD_PARSERS "Build TensorRT parsers" ON)
option(BUILD_SAMPLES "Build TensorRT samples" ON)
option(USE_TORCH "Build Torch" OFF)
if (USE_TORCH)
add_definitions(-DUSE_TORCH)
endif()
option(USE_FP16 "Build fp16" OFF)
if (USE_FP16)
add_definitions(-DUSE_FP16)
endif()
add_definitions(-DPARAM_PATH)
add_definitions(-DPARAM_XML="${PARAM_PATH}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "-Wno-deprecated-declarations ${CMAKE_CXX_FLAGS} -DBUILD_SYSTEM=cmake_oss")
############################################################################################
# Cross-compilation settings
set_ifndef(TRT_PLATFORM_ID "x86_64")
message(STATUS "Targeting TRT Platform: ${TRT_PLATFORM_ID}")
############################################################################################
# Debug settings
set(TRT_DEBUG_POSTFIX _debug CACHE STRING "suffix for debug builds")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Building in debug mode ${DEBUG_POSTFIX}")
endif()
############################################################################################
# Dependencies
set(DEFAULT_CUDA_VERSION 11.0)
set(DEFAULT_CUDNN_VERSION 8.0)
set(DEFAULT_PROTOBUF_VERSION 3.0.0)
set(DEFAULT_CUB_VERSION 1.8.0)
# Dependency Version Resolution
set_ifndef(CUDA_VERSION ${DEFAULT_CUDA_VERSION})
message(STATUS "CUDA version set to ${CUDA_VERSION}")
set_ifndef(CUDNN_VERSION ${DEFAULT_CUDNN_VERSION})
message(STATUS "cuDNN version set to ${CUDNN_VERSION}")
set_ifndef(PROTOBUF_VERSION ${DEFAULT_PROTOBUF_VERSION})
message(STATUS "Protobuf version set to ${PROTOBUF_VERSION}")
find_package(Threads REQUIRED)
if (BUILD_PLUGINS OR BUILD_PARSERS)
include(third_party/zlib.cmake)
include(third_party/protobuf.cmake)
endif()
if(NOT CUB_ROOT_DIR)
set(CUB_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cub CACHE STRING "directory of CUB installation")
endif()
## find_package(CUDA) is broken for cross-compilation. Enable CUDA language instead.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
find_package(CUDA ${CUDA_VERSION} REQUIRED)
endif()
include_directories(
${CUDA_INCLUDE_DIRS}
${CUDNN_ROOT_DIR}/include
)
find_library(CUDNN_LIB cudnn HINTS
${CUDA_TOOLKIT_ROOT_DIR} ${CUDNN_ROOT_DIR} PATH_SUFFIXES lib64 lib)
find_library(CUBLAS_LIB cublas HINTS
${CUDA_TOOLKIT_ROOT_DIR} PATH_SUFFIXES lib64 lib lib/stubs)
find_library(CUBLASLT_LIB cublasLt HINTS
${CUDA_TOOLKIT_ROOT_DIR} PATH_SUFFIXES lib64 lib lib/stubs)
if(BUILD_PARSERS)
configure_protobuf(${PROTOBUF_VERSION})
endif()
find_library_create_target(nvinfer nvinfer SHARED ${TRT_LIB_DIR})
find_library_create_target(nvuffparser nvparsers SHARED ${TRT_LIB_DIR})
find_library(CUDART_LIB cudart HINTS ${CUDA_TOOLKIT_ROOT_DIR} PATH_SUFFIXES lib lib64)
find_library(RT_LIB rt)
set(CUDA_LIBRARIES ${CUDART_LIB})
############################################################################################
# TensorRT
if(BUILD_PLUGINS)
add_subdirectory(plugin)
else()
find_library_create_target(nvinfer_plugin nvinfer_plugin SHARED ${TRT_OUT_DIR} ${TRT_LIB_DIR})
endif()
if(BUILD_PARSERS)
add_subdirectory(parsers)
else()
find_library_create_target(nvcaffeparser nvparsers SHARED ${TRT_OUT_DIR} ${TRT_LIB_DIR})
find_library_create_target(nvonnxparser nvonnxparser SHARED ${TRT_OUT_DIR} ${TRT_LIB_DIR})
endif()
#if(BUILD_SAMPLES)
# add_subdirectory(samples)
#endif()
bazel编译
资料
awesome baze 超多资源l
编译构建工具-bazel
Bazel 使用总结
Bazel & CMake
学习笔记
cache
Bazel 编译生成的缓存文件一般保存在项目目录下以 bazel-* 为名称的目录下,所以尽量不要在项目中创建以 bazel-* 为名称的文件夹,避免和缓存文件夹冲突
包的可见性(Package Visibility)
为了实现代码和模块之间的隔离,默认情况下 Package 只能看到自己 BUILD 内的 target。Bazel 提供了一些机制控制 Package 中 target 的可见性
- 对package定义
package(default_visibility = ["//visibility:public"]) # BUILD 文件内所有 target 全局可见
package(default_visibility = ["//src:__pkg__"]) # 基于目录的部分可见
- 对target定义
java_proto_library(
name = "transmission_object_java_proto",
deps = [":transmission_object_proto"],
visibility = ["//src:__pkg__"],
)
load
load 加载 Bazel 脚本文件(WORKSPACE、BUILD、bzl 文件), 用于从其他文件载入规则
load(":archive.bzl", "archive") # 从 archive.bzl 文件载入 archive 规则(函数)
cc_binary, cc_library
*_binary 规则:指定生成相应语言的可执行程序。cc_binary表示c++可执行程序.
*_library 规则:指定生成相应语言的库。
*_test 规则:是一个特殊的bianry规则,通常用于自动化测试。
# 静态库
cc_library(
name = "libstatic",
srcs = ["static.c"],
hdrs = ["static.h"],
linkstatic = True,
)
# 动态库
cc_binary(
name = "libfunc.so",
#name = "func",#必须写成libfunc.so,否则编译不过
srcs = ["func.h","func.c"],
linkshared = True,
)
cc_binary
- srcs: 允许的文件类型:
C and C++ source files: .c, .cc, .cpp, .cxx, .c++, .C
C and C++ header files: .h, .hh, .hpp, .hxx, .inc, .inl, .H
Assembler with C preprocessor: .S
Archive: .a, .pic.a
“Always link” library: .lo, .pic.lo
Shared library, versioned or unversioned: .so, .so.*version*
Object file: .o, .pic.o
以及产生这些文件的所有规则。 根据gcc约定,不同的扩展名表示不同的编程语言。
- copts: List of strings; optional将这些选项添加到C ++编译命令。
- includes : List of strings; optional 每个字符串都以-isystem开头,并添加到COPTS中。 与COPTS不同,这些标志是为此规则以及依赖于此规则的每个规则添加的。 (注意:不是它所依赖的规则!)。 如有疑问,请在COPTS上添加“ -I”标志。
- linkstatic: 创建静态库, 对于cc_binary和cc_test:以静态模式链接二进制文件。 对于cc_library.linkstatic:linkstatic = True表示仅允许静态链接,因此不会产生.so。 linkstatic = False不会阻止创建静态库。
- linkshared: 创建共享库
cc_import
cc_import(
name = "func",
hdrs = ["include/func.h"],
shared_library = "lib/libfunc.so",
)
cc_import(
name = "static",
hdrs = ["include/static.h"],
static_library = "lib/libstatic.a",
)
# main.cpp 链接两个库
cc_binary(
name = "link_static_shared",
srcs = ["main.c"],
deps = [":func",":static"],
copts = ["-Ilink/include"],
)
apollo cyber
submodule
git submodule add URL <path>
-b 指定分支版本:
git submodule add -b branchname URL <path>
下载所有代码的时候要用:
git clone --recurse-submodules URL