|
| 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 | +``` |
0 commit comments