开放代码社区 › Driving SDK 昇腾自动驾驶加速库

Driving SDK 昇腾自动驾驶加速库

开发工具C++

Driving SDK 是面向昇腾 NPU 平台的自动驾驶算子和模型加速库,提供高性能算子与模型加速接口,支持 PyTorch 框架及 ONNX 模型转换,适用于 BEVFormer 等感知、规划、端到端自动驾驶模型的训练与推理加速场景。

AI/机器学习Web后端前端工具部署/运维
作者:用户6868语言:C++更新:2026-10-27
仓库地址
https://gitee.com/ascend/DrivingSDK.git

前往原仓库

README

# 通知: 本项目已经正式迁移至 [Gitcode](https://gitcode.com/Ascend/DrivingSDK) 平台

# Driving SDK

# 简介

Driving SDK是基于昇腾NPU平台开发的适用于自动驾驶场景的算子和模型加速库,提供了一系列高性能的算子和模型加速接口,支持PyTorch框架。


# 安装
## 前提条件
1. 本项目依赖昇腾提供的pytorch_npu包和CANN包,需要先安装对应版本的pytorch_npu和CANN软件包,具体配套关系见pytorch仓[README](https://gitee.com/ascend/pytorch)。
请参考昇腾官方文档[Pytorch框架训练环境准备](https://hiascend.com/document/detail/zh/ModelZoo/pytorchframework/ptes/ptes_00001.html)。
2. 使用`pip3 install -r requirements.txt` 安装python依赖,`requirements.txt`文件位于项目根目录下。
3. 如果您需要编译`ONNX`插件,请安装`protobuf-devel-3.14.0`, 在`centos` 系统上可以执行`yum install protobuf-devel-3-14.0`,否则请将`CMakePresets.json`中的`ENABLE_ONNX`选项改为`FALSE`,`CMakePresets.json`文件位于项目根目录下。
4. 建议您在准备好环境后,使用`umask 0027`将umask调整为0027,以保证文件权限正确。
5. 建议您以非root用户身份执行以下操作。
6. 使用gcc编译本仓时,推荐使用gcc 10.2版本。

## 从发布包安装
当前并未正式发布whl包 ,请参考源码安装方式。
## 从源码安装
#### 1. 克隆原始仓。
```shell
git clone https://gitee.com/ascend/DrivingSDK.git -b master
```
#### 2. 编译Driving SDK。
> 注意:请在仓库根目录下执行编译命令
```shell
bash ci/build.sh --python=3.8
```
参数`--python`指定编译过程中使用的python版本,支持 3.8 及以上版本,缺省值为 3.8。请参考[编译指导](https://gitee.com/ascend/DrivingSDK/blob/master/docs/get_started/compile.md)获取更多编译细节。

生成的whl包在`DrivingSDK/dist`目录下, 命名规则为`mx_driving-1.0.0+git{commit_id}-cp{python_version}-linux_{arch}.whl`。

#### 3. 安装Driving SDK。
```shell+
cd DrivingSDK/dist
pip3 install mx_driving-1.0.0+git{commit_id}-cp{python_version}-linux_{arch}.whl
```
如需要保存安装日志,可在`pip3 install`命令后添加`--log <PATH>`参数,并对您指定的目录<PATH>做好权限控制。


#### 配套关系

DrivingSDK支持的CPU架构,Python,PyTorch和torch_npu版本对应关系如下:

| Gitee分支 |  CPU架构 |  支持的Python版本 | 支持的PyTorch版本 | 支持的torch_npu版本 |
|-----------|-----------|-------------------|-------------------|---------------------|
| master    | x86&aarch64|Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.1.0|v2.1.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.5.1|v2.5.1|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.6.0|v2.6.0|
| branch_v7.1.RC1   | x86&aarch64|Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.1.0|v2.1.0-7.1.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.5.1|v2.5.1-7.1.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.6.0|v2.6.0-7.1.0|
| branch_v7.0.RC1    | x86&aarch64|Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.1.0|v2.1.0-7.0.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.3.1|v2.3.1-7.0.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.4.0|v2.4.0-7.0.0|
| branch_v6.0.0    | x86&aarch64|Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.1.0|v2.1.0-6.0.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.3.1|v2.3.1-6.0.0|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.4.0|v2.4.0-6.0.0|
| branch_v6.0.0-RC3    | x86&aarch64|Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.1.0|v2.1.0-6.0.rc3|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.3.1|v2.3.1-6.0.rc3|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x,Python3.11.x|2.4.0|v2.4.0-6.0.rc3|
| branch_v6.0.0-RC2    |x86&aarch64 |    Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x,Python3.10.x|1.11.0|v1.11.0-6.0.rc2|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x|2.1.0|v2.1.0-6.0.rc2|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x|2.2.0|v2.2.0-6.0.rc2|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x|2.3.1|v2.3.1-6.0.rc2|
| branch_v6.0.0-RC1    |x86&aarch64 |    Python3.7.x(>=3.7.5),Python3.8.x,Python3.9.x,Python3.10.x|1.11.0|v1.11.0-6.0.rc1|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x|2.1.0|v2.1.0-6.0.rc1|
|           |       |Python3.8.x,Python3.9.x,Python3.10.x|2.2.0|v2.2.0-6.0.rc1|



# 卸载
Pytorch 框架训练环境的卸载请参考昇腾官方文档[Pytorch框架训练环境卸载](https://hiascend.com/document/detail/zh/ModelZoo/pytorchframework/ptes/ptes_00032.html)。
Driving SDK的卸载只需执行以下命令:
```shell
pip3 uninstall mx_driving
```

# 快速上手
```python
import torch, torch_npu
from mx_driving.common import scatter_max
updates = torch.tensor([[2, 0, 1, 3, 1, 0, 0, 4], [0, 2, 1, 3, 0, 3, 4, 2], [1, 2, 3, 4, 4, 3, 2, 1]], dtype=torch.float32).npu()
indices = torch.tensor([0, 2, 0], dtype=torch.int32).npu()
out = updates.new_zeros((3, 8))
out, argmax = scatter_max(updates, indices, out)
```

# 特性介绍
## 目录结构及说明
```
.
├── kernels                     # 算子实现
│  ├── op_host
│  ├── op_kernel
│  └── CMakeLists.txt
├── onnx_plugin                 # onnx框架适配层
├── mx_driving
│  ├── __init__.py
│  ├── csrc                     # 加速库API适配层
│  └── ...
├── model_examples              # 自动驾驶模型示例
│  └── BEVFormer                # BEVFormer模型示例
├── ci                          # ci脚本
├── cmake                       # cmake脚本
├── CMakeLists.txt              # cmake配置文件
├── CMakePresets.json           # cmake配置文件
├── docs                        # 文档
|  ├── api                      # 算子api调用文档
|  └── ...
├── include                     # 头文件
├── LICENSE                     # 开源协议
├── OWNERS                      # 代码审查
├── README.md                   # 项目说明
├── requirements.txt            # 依赖
├── scripts                     # 工程脚本
├── setup.py                    # whl打包配置
└── tests                       # 测试文件

```
## 算子清单
请参见[算子清单](https://gitee.com/ascend/DrivingSDK/blob/master/docs/api/README.md)。
## 支持特性
- [x] 支持PyTorch 2.1.0,2.3.1,2.4.0
- [x] 支持ONNX模型转换,训推一体
- [ ] 支持图模式
## onnx转换om
转换前需要手动添加环境变量
```shell
# 查看mx_driving安装路径
pip3 show mx_driving
export ASCEND_CUSTOM_OPP_PATH=xxx/site-packages/mx_driving/packages/vendors/customize/
export LD_LIBRARY_PATH=xxx/site-packages/mx_driving/packages/vendors/customize/op_api/lib/:$LD_LIBRARY_PATH
```

## 模型清单
DrivingSDK仓提供了包括感知、规划、端到端、VLA等自动驾驶模型基于昇腾机器的实操案例。每个模型都有详细的使用指导,后续将持续增加和优化典型模型。使用过程中,若遇到报错问题,可查看[自动驾驶模型FAQ](https://gitee.com/ascend/DrivingSDK/blob/master/docs/faq/model_faq.md)自助解决,或在[Issues](https://gitee.com/ascend/DrivingSDK/issues)中留言。如下列表中Released为Y的表示已经过测试验证,N的表示开发自验通过。

|  Model   | 8p-Atlas 800T A2性能(FPS)  | 8