1. 安装前提
1.1 安装 Ubuntu 系统
要求安装 Ubuntu(18.04+)
以上版本系统。
1.2 安装 NVIDIA GPU 驱动
NVIDIA GPU Driver
版本 > 455, cuda > 11.1
。
1.3 安装 Docker
Docker
版本要求 19.03+
。
- Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install ca-certificates
curl gnupg lsb-release
- Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Use the following command to set up the stable repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- Create the docker group and add your user
sudo groupadd docker
sudo usermod -aG docker $USER
- Log out and log back in, then verify
docker run hello-world
1.4 安装 NVIDIA Container Toolkit
- Setup the stable repository and the GPG key
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
- updating the package listing and install
sudo apt-get update
sudo apt-get install -y nvidia-docker2
- Restart the Docker daemon to complete the installation
sudo systemctl restart docker
- verify
nvidia-docker version
或者
dpkg -l | grep nvidia-docker
2. 安装 Apollo
2.1 下载源码
# Using SSH
git clone git@github.com:ApolloAuto/apollo.git
# Using HTTPS
git clone https://github.com/ApolloAuto/apollo.git
2.2 切换到 master 分支
通过 git branch
查看如果已经是 master
分支则忽略该步骤。
cd apollo
git checkout master
2.3 添加环境变量
为方便起见,你可以设置环境变量 APOLLO_ROOT_DIR
,执行下面命令前确保 pwd
已经是 apollo
目录下
echo "export APOLLO_ROOT_DIR=$(pwd)" >> ~/.bashrc && source ~/.bashrc
2.4 运行 Apollo 开发容器
进入到下载的 apollo
目录下,执行命令:
bash docker/scripts/dev_start.sh
执行成功后会有下面的输出:
[ OK ] Congratulations! You have successfully finished setting up Apollo Dev Environment.
[ OK ] To login into the newly created apollo_dev_michael container, please run the following command:
[ OK ] bash docker/scripts/dev_into.sh
[ OK ] Enjoy!
2.5 执行命令进入容器
bash docker/scripts/dev_into.sh
2.6 在容器内进行编译
在容器内的 /apollo
目录下执行
./apollo.sh build
进行整体编译,或者
./apollo.sh build_opt
进行部分选项编译,编译成功后输出
(01:10:49) INFO: Elapsed time: 287.913s, Critical Path: 160.75s
(01:10:49) INFO: 25369 processes: 6857 remote cache hit, 17424 internal, 1088 local.
(01:10:49) INFO: Build completed successfully, 25369 total actions
==============================================
[ OK ] Done building apollo. Enjoy!
==============================================
如果编译过程中报错:
x86_64-linux-gnu-gcc-7: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
(00:52:42) INFO: Elapsed time: 1826.018s, Critical Path: 566.76s
(00:52:42) INFO: 17253 processes: 12 remote cache hit, 10163 internal, 7078 local.
(00:52:42) FAILED: Build did NOT complete successfully
可能是内存不够导致,按照下面方法设置交换内存后再重新编译
# 1. 创建分区文件,建立 16G 交换内存
sudo dd if=/dev/zero of=/swapfile bs=1k count=16384000
# 2.生成swap文件系统
sudo mkswap /swapfile
# 3. 激活swap文件
sudo swapon /swapfile
# 打开系统文件
vi /etc/fstab
# 添加如下行,让系统重启时能够自动挂载交换分区
/swapfile swap swap defaults 0 0
检查交换内存是否设置成功
$ free -h
total used free shared buff/cache available
Mem: 15G 2.8G 7.6G 92M 5.1G 12G
Swap: 16G 2.4G 14G
参考:
https://blog.csdn.net/zangba9624/article/details/118678416
https://blog.csdn.net/qq_36558538/article/details/88394318
3. 运行
3.1 编译 GPU 版本
参考:https://github.com/ApolloAuto/apollo/blob/master/docs/howto/how_to_launch_and_run_apollo.md
进入容器内执行命令
./scripts/apollo_clean.sh -a
./apollo.sh build_opt_gpu
编译成功后输出:
(01:36:03) INFO: Elapsed time: 1236.815s, Critical Path: 178.36s
(01:36:03) INFO: 30719 processes: 7275 remote cache hit, 18777 internal, 4667 local.
(01:36:03) INFO: Build completed successfully, 30719 total actions
==============================================
[ OK ] Done building apollo. Enjoy!
==============================================
3.2 运行
运行 ./scripts/bootstrap.sh
将在启用监控模块后启动 Dreamview 后台。
# Startup modules monitor and dreamview, the default option is start.
./scripts/bootstrap.sh [start | stop | restart]
输出如下:
$ ./scripts/bootstrap.sh
nohup: appending output to 'nohup.out'
[ OK ] Launched module monitor.
nohup: appending output to 'nohup.out'
[ OK ] Launched module dreamview.
Dreamview is running at http://localhost:8888
在浏览器中打开 http://localhost:8888,如下。但目前除监视器外没有其他模块在后台运行。
选择驾驶模式和地图
下载官方自带的 demo,同样是在容器内执行:
cd docs/demo_guide/
python3 record_helper.py demo_3.5.record
加载环境变量
source cyber/setup.bash
否则会报错 cyber_recorder: command not found
然后循环播放 demo(不想循环播放的话去掉 -l
就行):
cyber_recorder play -f docs/demo_guide/demo_3.5.record -l
总结运行的整体步骤:
cd apollo/
sudo bash docker/scripts/dev_into.sh # 进入 apollo 的 docker 容器内
./scripts/bootstrap.sh # 启动检测模块和dreamview
# 运行 demo 的命令,或者执行其它命令
cyber_recorder play -f docs/demo_guide/demo_3.5.record -l # 循环播放 demo
# 如果报错 cyber_recorder: command not found 执行下面语句
source cyber/setup.bash