Skip to content

Commit 4d6ea01

Browse files
Support arm (#28)
* feat(examples): support aarch64 Co-authored-by: MegEngine <[email protected]>
1 parent 1b8c226 commit 4d6ea01

File tree

3 files changed

+126
-15
lines changed

3 files changed

+126
-15
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ MegFlow 提供快速视觉应用落地流程,最快 15 分钟搭建起视频
1414

1515
## HowTo
1616
* how to build and run
17-
* [run in 15 minutes](docs/how-to-build-and-run/run-in-15-minutes.zh.md)
17+
* [run with prebuilt .whl](docs/how-to-build-and-run/run-in-15-minutes.zh.md)
1818
* [build with docker](docs/how-to-build-and-run/build-with-docker.zh.md)
1919
* [build from source](docs/how-to-build-and-run/build-from-source.zh.md)
2020
* [build on win10](docs/how-to-build-and-run/build-on-win10.zh.md)
21+
* [build on armv8](docs/how-to-build-and-run/build-on-aarch64.zh.md)
2122
* [generate rtsp](docs/how-to-build-and-run/generate-rtsp.zh.md)
2223
* how to use
2324
* [tutorial01: image classification service](docs/how-to-add-my-service/01-single-classification-model.zh.md)
@@ -28,21 +29,21 @@ MegFlow 提供快速视觉应用落地流程,最快 15 分钟搭建起视频
2829

2930
## Current Support List
3031

31-
| 系统环境 | 支持情况 |
32-
| - | - |
33-
| Windows 10 wsl2 | ✔️ |
34-
| Windows 10 docker | ✔️ |
35-
| x86 Ubuntu16.04 有 GPU | ✔️ |
36-
| x86 Ubuntu18.04 无 GPU | ✔️ |
37-
| x86 macos | ✔️ |
38-
| ARM | / |
32+
| 系统环境 | 支持情况 |
33+
| ---------------------- | -------- |
34+
| Windows 10 wsl2 | ✔️ |
35+
| Windows 10 docker | ✔️ |
36+
| x86 Ubuntu16.04 有 GPU | ✔️ |
37+
| x86 Ubuntu18.04 无 GPU | ✔️ |
38+
| x86 macos | ✔️ |
39+
| ARM | ✔️ |
3940

4041
| Python 版本 | 支持情况 |
41-
| - | - |
42-
| 3.6 | ✔️ |
43-
| 3.7 | ✔️ |
44-
| 3.8 | ✔️ |
45-
| 3.9 | / |
42+
| ----------- | -------- |
43+
| 3.6 | ✔️ |
44+
| 3.7 | ✔️ |
45+
| 3.8 | ✔️ |
46+
| 3.9 | / |
4647

4748
## Built-in Applications
4849
* 猫猫围栏
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# aarch64 源码编译
2+
3+
## 一、测试环境
4+
华为鲲鹏 ARM 服务器,centOS 7.9
5+
6+
## 二、环境安装
7+
**gcc 需要 >= 7.5 版本,默认的 `aarch64-redhat-linux-gcc 4.8.5``__ARM_NEON` 没法用**
8+
```bash
9+
$ yum install -y centos-release-scl
10+
$ yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++
11+
$ source /opt/rh/devtoolset-8/enable
12+
$ gcc --version
13+
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
14+
...
15+
```
16+
17+
### 安装 Rust
18+
```bash
19+
$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
20+
```
21+
22+
成功后,`cargo` 应该可以正常执行
23+
```bash
24+
$ cargo --version
25+
cargo 1.53.0 (4369396ce 2021-04-27)
26+
```
27+
28+
> `cargo` 是 Rust 的包管理器兼编译辅助工具。类似 Java maven/go pkg/C++ CMake 的角色,更易使用。
29+
30+
### 安装 python3.x (推荐 conda)
31+
32+
打开 [miniconda 官网](https://docs.conda.io/en/latest/miniconda.html) 下载 miniconda 安装包,修改权限并安装。
33+
34+
```bash
35+
$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
36+
$ chmod a+x Miniconda3-latest-Linux-x86_64.sh
37+
$ ./Miniconda3-latest-Linux-x86_64.sh
38+
```
39+
40+
安装时接受 conda 修改默认 .bashrc 环境变量(zsh 用户还需自行修改 .zshrc 中的 conda initialize 配置)。成功后 `conda` 可正常运行
41+
```bash
42+
$ conda --version
43+
conda 4.10.3
44+
```
45+
46+
创建一个 Python3.x(这里以 3.8 为例) 的环境,激活。
47+
```bash
48+
$ conda create --name py38 python=3.8
49+
$ conda activate py38
50+
```
51+
52+
53+
## 三、编译
54+
55+
编译底层 Rust 组件,安装 Python module
56+
57+
```bash
58+
$ git clone --recursive https://github.com/MegEngine/MegFlow --depth=1
59+
$ cd MegFlow
60+
$ cargo build
61+
waiting ...
62+
$ cd flow-python
63+
$ python3 setup.py install --user
64+
```
65+
66+
P.S. 默认 ffmpeg 依赖自动从 github 上拉取源码构建,这会使得首次构建的时间较长。若希望缩短首次构建时间,或者希望依赖一个指定版本的 ffmpeg,可以启用环境变量`CARGO_FEATURE_PREBUILD`并参考[rust-ffmpeg](https://github.com/zmwangx/rust-ffmpeg/wiki/Notes-on-building)自行构建
67+
68+
69+
## 四、Python“开机自检”
70+
```bash
71+
$ cd examples
72+
$ cargo build --example run_with_plugins --release # 编译出 megflow bin
73+
$ ln -s ../../target/example/run_with_plugins
74+
$ ./run_with_plugins -p logical_test
75+
```
76+
`logical_test` 是 examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。
77+
78+
`run_with_plugins` 是计算图的实现。编译完成之后不再需要 `cargo``Rust`,使用者只需要
79+
80+
* `import megflow`成功
81+
* `run_with_plugins -h` 正常
82+
83+
84+
## 五、Python Built-in Applications
85+
86+
接下来开始运行好玩的 Python 应用
87+
88+
* [猫猫围栏运行手册](../../flow-python/examples/cat_finder/README.md)
89+
* 图片注册猫猫
90+
* 部署视频围栏,注册的猫离开围栏时会发通知
91+
* 未注册的不会提示
92+
* [电梯电瓶车告警](../../flow-python/examples/electric_bicycle/README.md)
93+
* 电梯里看到电瓶车立即报警
94+
* Comming Soon
95+
* OCR: 通用字符识别
96+
97+
98+
## 六、其他选项
99+
```bash
100+
$ cargo run --example graph -- ${args} # 测试 MegFlow 的延迟/吞吐/调度开销, 更多使用说明通过--help 查看
101+
$ cargo run --example run_with_plugins -- ${args} # 基于插件 + 参数文件形式运行 MegFlow, 更多说明通过--help 查看
102+
$ export RUST_LOG=LOG_LEVEL // 设置日志级别, 例如 INFO, TRACE..
103+
$ cargo build [--release] // 编译
104+
$ cargo check // 快速编译,不执行 link
105+
$ cargo test [target] // 执行单元测试
106+
```

flow-python/examples/warehouse/detection_yolox/lite.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def __init__(
8888
net.load(path)
8989

9090
self.net = net
91+
self.device = device
9192
self.cls_names = cls_names
9293
self.decoder = decoder
9394
self.num_classes = 80
@@ -154,7 +155,10 @@ def inference(self, img):
154155

155156
outputs = self.lite_postprocess(outputs[0], list(self.test_size))
156157
outputs = outputs[np.newaxis, :]
157-
output = mge.tensor(outputs)
158+
if "gpu" in self.device:
159+
output = mge.tensor(outputs)
160+
else:
161+
output = mge.tensor(outputs, device="cpux")
158162

159163
ret = postprocess(output, self.num_classes, self.confthre,
160164
self.nmsthre)

0 commit comments

Comments
 (0)