running Apollo on orin(arm64/aarch64) 移植记录

好消息~apollo已经发布了orin版本:https://github.com/ApolloAuto/apollo/issues/15090

另外还有4090显卡的支持:

https://github.com/ApolloAuto/apollo/issues/14821

最近一段时间一直在研究怎么把apollo移植到nvidia jetson agx orin上,最后除了perception以及localization模块没有编译成功,其他的模块都编译成功并且可以运行了,在这里先简单记录下我做的工作。

一、环境

1. Nvidia jetson agx orin:

cuda11.4.1

libtorch 1.12.0

r35.1

ubuntu20.04

python3.8

2. apollo:

8.0.0

二、移植过程

1. 改动dev_start.sh

用nvidia-l4t-base镜像代替apollo的aarch64的镜像,即

DEV_IMAGE="nvcr.io/nvidia/l4t-base:r35.1.0"

2. 创建容器

./apollo/docker/scripts/dev_start.sh

如果遇到报错:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/containerd/io.containerd.runtime.v2.task/moby/d72fc1c3f26d44b3e50ab163968859acf86c07cf1811f3549701b4ec72d53788/log.json: no such file or directory): exec: "nvidia-container-runtime": executable file not found in $PATH: <nil>: unknown.

 在orin终端中输入

sudo apt -f install

 会自动修复nvidia-docker缺失的依赖

3. 进入容器

./apollo/docker/scripts/dev_into.sh

4. 编译一些cyber以及modules的依赖

在编译依赖之前先设置一下下载源,编辑 apollo/docker/rcfiles/sources.list.cn.aatch64,替换成20.04的focal版本

deb [arch=arm64] http://mirrors.aliyun.com/ubuntu-ports/ focal main restricted universe multiverse
deb [arch=arm64] http://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted universe multiverse
deb [arch=arm64] http://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
deb [arch=arm64] http://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted universe multiverse

然后把rcfiles文件夹复制到/opt/apollo下;

然后是在docker内安装cuda,直接去官网下载cuda11.4的sh文件,然后在docker内运行就可以。这里贴一下命令行获取cuda11.4的命令:

wget https://developer.download.nvidia.com/compute/cuda/11.4.1/local_installers/cuda_11.4.1_470.57.02_linux_sbsa.run

(后续编译perception模块时发现boost缺好多定义,检查了一下发现apollo脚本内写的boost版本是1.74.0,但实际上使用的是1.71.0,所以直接使用1.71.0版本的boost库,可以吧install_boost.sh内的boost版本改为1_71_0)

此外在apollo/docker/build/installers里面有很多自带的依赖脚本,我整理了一下顺序写成了一个.sh文件,这个文件需要在容器内运行。

#!/usr/bin/env bash

###############################################################################
#
# Author: Scott Deng
# This file is used to install dependences for apollo running on orin.
# Email: dengx@turing.cc
#
###############################################################################

# Fail on first error.
set -e

MY_MODE="${1:-download}"

cd "$(dirname "${BASH_SOURCE[0]}")"
. ./installer_base.sh

ARCH="$(uname -m)"

cp -r ../rcfiles /opt/apollo/

bash ${CURR_DIR}/install_minimal_environment.sh cn
# bazel
cp -f bazel-3.7.1-linux-arm64 "${SYSROOT_DIR}/bin/bazel"
cp /opt/apollo/rcfiles/bazel_completion.bash /etc/bash_completion.d/bazel
PKG_NAME="buildifier-${BUILDTOOLS_VERSION}-linux-arm64"
CHECKSUM="19d5b358cb099e264086b26091661fd7548df0a2400e47fd98238cfe0a3e67f9"
DOWNLOAD_LINK="https://apollo-system.cdn.bcebos.com/archive/6.0/${PKG_NAME}"
download_if_not_cached "${PKG_NAME}" "${CHECKSUM}" "${DOWNLOAD_LINK}"
cp -f ${PKG_NAME} "${SYSROOT_DIR}/bin/buildifier"
chmod a+x "${SYSROOT_DIR}/bin/buildifier"
rm -rf ${PKG_NAME}
info "Done installing bazel ${BAZEL_VERSION} with buildifier ${BUILDTOOLS_VERSION}"
# Note(storypku):
# Used by `apollo.sh config` to determine native cuda compute capability.
bash ${CURR_DIR}/install_deviceQuery.sh

bash ${CURR_DIR}/install_cmake.sh
bash ${CURR_DIR}/install_llvm_clang.sh
bash ${CURR_DIR}/install_cyber_deps.sh
bash ${CURR_DIR}/install_qa_tools.sh
bash ${CURR_DIR}/install_visualizer_deps.sh
bash ${CURR_DIR}/install_modules_base.sh

#gpu support
apt_get_update_and_install \
    libopenblas-dev \
    libatlas-base-dev \
    liblapack-dev
# Note(infra): build magma before mkl
info "Install Magma ..."
bash ${CURR_DIR}/install_magma.sh
##============================================================##
# libtorch_gpu
bash ${CURR_DIR}/install_mkl.sh
unzip libtorch_gpu.zip
mv libtorch_gpu /usr/local/
mv libcudnn.so.8.0.0 /usr/lib/aarch64-linux-gnu/
ln -s /usr/lib/aarch64-linux-gnu/libcudnn.so.8.0.0 /usr/lib/aarch64-linux-gnu/libcudnn.so.8

bash ${CURR_DIR}/install_ordinary_modules.sh
bash ${CURR_DIR}/install_drivers_deps.sh
bash ${CURR_DIR}/install_dreamview_deps.sh
bash ${CURR_DIR}/install_contrib_deps.sh
bash ${CURR_DIR}/install_release_deps.sh

其中libtorch_gpu.zip是我在orin上本地编译的,1.12.0版本,编译参考:

https://zhuanlan.zhihu.com/p/585468425

bazel-3.7.1建议自己在其他地方下载好然后移动到docker里,脚本下载可能会因为网络问题失败

另外编译完boost1.74.0后,在编译apollo的一些模块时候会出现undefined reference to boost::filesystem::detail::directory_iterator_construct(xxx的错误,我看了下好像是缺少一个重载,于是这边我重新从源码编译了boost,修改boost_1_74_0/libs/filesystem/src/directory.cpp文件,;在里面找到friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct然后在他下面添加声明

friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec);

定义就是复制一份原来的friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct,并在里面令opts=0;

(后续编译perception模块时发现boost缺好多定义,检查了一下发现apollo脚本内写的boost版本是1.74.0,但实际上使用的是1.71.0,所以直接使用1.71.0版本的boost库)

补充:

还需要将cuda的一些头文件如cudnn.h、cudnn_version.h以及Nv开头的一些头文件放到容器内;

另外还有arm架构下的libcu60的一些库文件可以从Index of /ubuntu/pool/main/i/icu下载,找到libicu60_60.2-6ubuntu1_arm64.deb下载,然后在docker内用dpkg安装即可。

5. 开始编译

首先编译cyber,在编译cyber之前同样需要修改一些文件:

由于aarch64不支持-mavx以及-mavx2选项,所以需要删除apollo/scripts/apollo_build.sh中的这两个选项。

另外如果编译时将warning视为了error导致编译失败,可以通过注释apollo/tools/bazel.rc的35~40行进行解决

编译cyber:

./apollo.sh build cyber

然后用类似下面的命令编译apollo除了perception、localization的其他模块,

./apollo.sh build v2x prediction control

现在应该没问题了。

运行dreamview可以用simcontrol简单的跑个仿真。(用火狐浏览器打开localhost:8888,会显示黑屏,我是用另一台x86的电脑的chrome连接到orin的dreamiew的)

写文的时候已经编译完挺久了,可能会有遗漏,如果编译中遇到其他问题可以评论一下,大家一起交流一下。

三、关于perception和localization的编译

localization模块由于apollo官方并没有给出arm64的msf_localization.so,我也没找到源码来编译,所以编译localization会报错。

perception编译不起来是因为apollo只支cuda10+tensorrt7,支持orin的apollo版本还在开发中,最早在2023年7月会发布,所以编译的时候回报错诸如“DimsCHW” in Nvinfer1 does not  name a type,因为DimsCHW这些接口在tensorrt8里被废弃了,如果想要给apollo升级到tensorrt8,那么就要自己定义一些wrapper来改写接口,工作量挺大的;可以参考

https://github.com/ApolloAuto/apollo/issues/14858

然后为什么不让orin的cuda和tensorrt版本降级呢,因为我没有找到适用于orin的cuda10,nvidia官网上适合orin使用的最早的版本也只到11.4.0而11.4必须搭配rensorrt8;如果使用11.3会报错不支持“compute_86"

关于perception的编译可以参考(未完成):

running Apollo on orin(arm64/aarch64) Perception 编译记录_Scott_D_的博客-CSDN博客

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
In file included from /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/include/apollo_common/apollo_app.h:46:0, from /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/src/apollo_app.cc:33: /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/include/apollo_common/log.h:40:10: fatal error: glog/logging.h: No such file or directory #include <glog/logging.h> ^~~~~~~~~~~~~~~~ compilation terminated. apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/build.make:62: recipe for target 'apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/src/apollo_app.cc.o' failed make[2]: *** [apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/src/apollo_app.cc.o] Error 1 make[2]: *** Waiting for unfinished jobs.... In file included from /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/include/apollo_common/adapters/adapter_manager.h:48:0, from /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/src/adapters/adapter_manager.cc:33: /home/acceler/code/apollo_ros/apollo_ros/src/apollo.ros-1.0.0-master/apollo_common/include/apollo_common/adapters/adapter.h:49:10: fatal error: glog/logging.h: No such file or directory #include <glog/logging.h> ^~~~~~~~~~~~~~~~ compilation terminated. apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/build.make:110: recipe for target 'apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/src/adapters/adapter_manager.cc.o' failed make[2]: *** [apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/src/adapters/adapter_manager.cc.o] Error 1 CMakeFiles/Makefile2:3894: recipe for target 'apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/all' failed make[1]: *** [apollo.ros-1.0.0-master/apollo_common/CMakeFiles/apollo_common.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 54%] Linking CXX executable /home/acceler/code/apollo_ros/apollo_ros/devel/lib/IntegratedNavigation/IntegratedNavigation_node [ 54%] Built target IntegratedNavigation_node [ 55%] Linking CXX executable /home/acceler/code/apollo_ros/apollo_ros/devel/lib/TimeSynchronierProcess/timeSynchronierProcess_node [ 55%] Built target timeSynchronierProcess_node Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j4 -l4" failed
07-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值