重构: examples/ 两级结构 + 按硬件单元案例镜像 + MCU/DSP 跑通 + 时间tag + 公共镜像仓库
- 目录重组: coremark_images/bpu_model_perf_images/app_base_images -> examples/<案例>/<平台>/ - 六硬件单元案例镜像 (bpu/gpu/vpu+jpu/dsp/hbmem/mcu), 案例 Dockerfile 内编译, run.sh 自测 - app_base 三板基础镜像 (板型自动识别) + shell.sh 交互容器 + bench.sh 宿主对比 - MCU 跑通: BSP 固件经 remoteproc 拉起 (含版本记录 firmware/README.md) - VDSP 跑通: q8sample 固件自动装入 + device_op 设备补齐 - VPU+JPU 同镜像双路径 (H264/JPEG 各100帧) - 全部镜像 tag 统一 yymmdd_HHMMSS 时间戳 - 25 个镜像推送 BCR rlark 命名空间, 公共地址见 examples/README.md - install_docker.sh 增加 Ubuntu 版本检测 (22.04/24.04) + ip6table_raw 处理 - coremark 假成功修复 + 源码自动克隆 (65MB 不入库) Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
6ac89bd01f
commit
6faa932dce
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# 测试运行产物 (由各案例 run.sh/bench.sh 生成, 随时重跑再生, 不入库)
|
||||
examples/*/any/output/*
|
||||
!examples/*/any/output/**/report.md
|
||||
examples/app_base/any/output/*/artifacts/
|
||||
examples/app_base/any/output/*/bench_latest.json
|
||||
examples/app_base/any/output/*/case_images/
|
||||
|
||||
# 示例模型 (宿主机 /opt/hobot/model 已有且随固件更新, 不入库)
|
||||
examples/bpu_model_perf/*/example_fs/input/*.hbm
|
||||
examples/bpu_model_perf/*/example_fs/input/*.bin
|
||||
examples/bpu_model_perf/*/example_fs/input/*.bit
|
||||
|
||||
# 构建临时产物
|
||||
examples/bpu_model_perf/*/hrt_model_exec
|
||||
*.o
|
||||
|
||||
# coremark-pro 第三方源码 (65MB, build.sh 首次构建时自动从镜像克隆, 不入库)
|
||||
examples/coremark/any/coremark-pro/
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "coremark_images/coremark-pro"]
|
||||
path = coremark_images/coremark-pro
|
||||
url = https://github.com/eembc/coremark-pro.git
|
||||
181
README.md
181
README.md
@ -8,9 +8,15 @@
|
||||
- [目录结构](#目录结构)
|
||||
- [RDK S100 系列使用方法(Nash-e / Nash-m)](#rdk-s100-系列使用方法nash-e--nash-m)
|
||||
- [RDK X5 系列使用方法(Bayes-e)](#rdk-x5-系列使用方法bayes-e)
|
||||
- [RDK S600 使用方法(Nash-p)](#rdk-s600-使用方法nash-p)
|
||||
- [交互式进入容器](#交互式进入容器)
|
||||
- [task.json 协议说明](#taskjson-协议说明)
|
||||
- [输出结果说明](#输出结果说明)
|
||||
- [/app 案例基础镜像(app_base)](#app-案例基础镜像app_base)
|
||||
- [app_base 工具说明](#app_base-工具说明)
|
||||
- [app_base 目录结构](#app_base-目录结构)
|
||||
- [app_base 使用方法](#app_base-使用方法)
|
||||
- [app_base 基准对比](#app_base-基准对比)
|
||||
- [CoreMark-PRO CPU 性能测试工具](#coremark-pro-cpu-性能测试工具)
|
||||
- [工具说明](#工具说明-1)
|
||||
- [目录结构](#目录结构-1)
|
||||
@ -28,6 +34,9 @@
|
||||
|----------|----------|-----------------|-------------------|
|
||||
| RDK S100 / RDK S100P | Nash-e / Nash-m | >= 4.0.4-Beta | >= 4.0.4-20251015222314 |
|
||||
| RDK X5 / RDK X5 Module | Bayes-e | >= 3.3.3 | >= Sep-03-2025 |
|
||||
| RDK S600 | Nash-p | >= 5.1.0 | 无特殊要求 |
|
||||
|
||||
安装脚本自动检测系统 Ubuntu 版本(22.04 / 24.04)并适配,RDK S600 的 RDK OS V5.1.0 基于 Ubuntu 24.04。
|
||||
|
||||
|
||||
### 安装
|
||||
@ -47,9 +56,11 @@ bash install_docker/install_docker.sh
|
||||
|
||||
```text
|
||||
============================================================
|
||||
Docker 一键安装脚本 (Ubuntu 22.04 ARM64/x86_64)
|
||||
Docker 一键安装脚本 (Ubuntu 24.04 rdk os noble ARM64/x86_64)
|
||||
============================================================
|
||||
|
||||
[INFO] 检测 Ubuntu 版本...
|
||||
[OK] Ubuntu 基础版本: 24.04 (rdk os noble) ✓
|
||||
[INFO] 检查系统架构...
|
||||
[OK] 架构: aarch64 (ARM64) ✓
|
||||
[INFO] 检查运行权限...
|
||||
@ -130,35 +141,33 @@ bash install_docker/test_docker.sh
|
||||
|
||||
| 硬件平台 | BPU 架构 | 镜像名称 |
|
||||
|----------|----------|----------|
|
||||
| RDK S100 / RDK S100P | Nash-e / Nash-m | `hrt_perf_nashem:v3.7.3` |
|
||||
| RDK X5 / RDK X5 Module | Bayes-e | `hrt_perf_bayese:v1.24.5` |
|
||||
| RDK S100 / RDK S100P | Nash-e / Nash-m | `hrt_perf_nashem:<yymmdd_HHMMSS>` |
|
||||
| RDK X5 / RDK X5 Module | Bayes-e | `hrt_perf_bayese:<yymmdd_HHMMSS>` |
|
||||
| RDK S600 | Nash-p | `hrt_perf_nashp:<yymmdd_HHMMSS>` |
|
||||
|
||||
|
||||
### 目录结构
|
||||
|
||||
```
|
||||
bpu_model_perf_images/
|
||||
├── Dockerfile.nashem_perf # RDK S100 (Nash-e/Nash-m) Dockerfile
|
||||
├── Dockerfile.bayese_perf # RDK X5 (Bayes-e) Dockerfile
|
||||
├── docker_build_nashem.sh # RDK S100 镜像构建脚本
|
||||
├── docker_build_bayese.sh # RDK X5 镜像构建脚本
|
||||
├── docker_run_nashem_perf.sh # RDK S100 自动化 perf 运行脚本
|
||||
├── docker_run_bayese_perf.sh # RDK X5 自动化 perf 运行脚本
|
||||
├── docker_test_nashem.sh # RDK S100 交互式进入容器脚本
|
||||
├── docker_test_bayese.sh # RDK X5 交互式进入容器脚本
|
||||
├── workspace/
|
||||
│ ├── perf.py # 性能测试主脚本(两平台共用)
|
||||
│ └── entrypoint.sh # 容器入口脚本(两平台共用)
|
||||
├── example_fs/ # RDK S100 示例输入输出
|
||||
examples/bpu_model_perf/
|
||||
├── nashem/ # S100: Dockerfile + build.sh + run.sh + test.sh + workspace/ + example_fs/
|
||||
├── bayese/ # X5: 同上
|
||||
└── nashp/ # S600: 同上 (base 为 ubuntu:24.04)
|
||||
│ ├── input/
|
||||
│ │ ├── task.json # 输入协议文件
|
||||
│ │ └── *.hbm # 模型文件(放在此处)
|
||||
│ └── output/
|
||||
│ └── result.json # 运行后自动生成
|
||||
└── example_fs_bayese/ # RDK X5 示例输入输出
|
||||
├── example_fs_bayese/ # RDK X5 示例输入输出
|
||||
│ ├── input/
|
||||
│ │ ├── task.json # 输入协议文件
|
||||
│ │ └── *.hbm / *.bin # 模型文件(放在此处)
|
||||
│ └── output/
|
||||
│ └── result.json # 运行后自动生成
|
||||
└── example_fs_nashp/ # RDK S600 示例输入输出
|
||||
├── input/
|
||||
│ ├── task.json # 输入协议文件
|
||||
│ └── *.hbm / *.bin # 模型文件(放在此处)
|
||||
│ └── *.hbm # 模型文件(放在此处)
|
||||
└── output/
|
||||
└── result.json # 运行后自动生成
|
||||
```
|
||||
@ -166,19 +175,21 @@ bpu_model_perf_images/
|
||||
|
||||
```bash
|
||||
# RDK X5 / RDK X5 module
|
||||
docker pull ccr-29eug8s3-pub.cnc.bj.baidubce.com/public/hrt_perf_bayese:v1.24.5
|
||||
docker pull ccr-29eug8s3-pub.cnc.bj.baidubce.com/public/hrt_perf_bayese:<yymmdd_HHMMSS>
|
||||
|
||||
# RDK S100 / RDK S100P
|
||||
docker pull ccr-29eug8s3-pub.cnc.bj.baidubce.com/public/hrt_perf_nashem:v3.7.3
|
||||
docker pull ccr-29eug8s3-pub.cnc.bj.baidubce.com/public/hrt_perf_nashem:<yymmdd_HHMMSS>
|
||||
```
|
||||
|
||||
RDK S600 暂无预打包镜像,需在 S600 板端通过 `docker_build_nashp.sh` 自行构建。
|
||||
|
||||
### RDK S100 系列使用方法(Nash-e / Nash-m)
|
||||
|
||||
**第一步:构建镜像**(只需构建一次,之后可直接交付镜像)
|
||||
|
||||
```bash
|
||||
cd bpu_model_perf_images
|
||||
bash docker_build_nashem.sh
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash build.sh
|
||||
```
|
||||
|
||||
构建脚本会自动从板子上找到 `hrt_model_exec`(`which hrt_model_exec`)并打包进镜像,无需手动操作。
|
||||
@ -197,7 +208,7 @@ bash docker_build_nashem.sh
|
||||
**第三步:运行**
|
||||
|
||||
```bash
|
||||
bash docker_run_nashem_perf.sh
|
||||
bash run.sh
|
||||
```
|
||||
|
||||
运行脚本将 `example_fs/input` 挂载为容器内 `/workspace/input`,`example_fs/output` 挂载为 `/workspace/output`。
|
||||
@ -239,8 +250,8 @@ Results saved to: /workspace/output/result.json
|
||||
**第一步:构建镜像**
|
||||
|
||||
```bash
|
||||
cd bpu_model_perf_images
|
||||
bash docker_build_bayese.sh
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash build.sh
|
||||
```
|
||||
|
||||
**第二步:准备输入**
|
||||
@ -257,10 +268,43 @@ bash docker_build_bayese.sh
|
||||
**第三步:运行**
|
||||
|
||||
```bash
|
||||
bash docker_run_bayese_perf.sh
|
||||
bash run.sh
|
||||
```
|
||||
|
||||
|
||||
### RDK S600 使用方法(Nash-p)
|
||||
|
||||
RDK S600 的 RDK OS V5.1.0 基于 Ubuntu 24.04 (glibc 2.39),因此镜像 base 为 `ubuntu:24.04`(22.04 基底的 glibc 2.35 无法运行 S600 宿主机上的 BPU 工具链)。
|
||||
|
||||
**第一步:构建镜像**(只需构建一次,之后可直接交付镜像)
|
||||
|
||||
```bash
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash build.sh
|
||||
```
|
||||
|
||||
构建脚本会自动从板子上找到 `hrt_model_exec`(`which hrt_model_exec`)并打包进镜像,无需手动操作。
|
||||
|
||||
**第二步:准备输入**
|
||||
|
||||
将模型文件(`.hbm`)放入 `example_fs_nashp/input/`,并编辑 `example_fs_nashp/input/task.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"model_relative_path": "your_model.hbm",
|
||||
"frame_count": 200
|
||||
}
|
||||
```
|
||||
|
||||
**第三步:运行**
|
||||
|
||||
```bash
|
||||
bash run.sh
|
||||
```
|
||||
|
||||
运行脚本将 `example_fs_nashp/input` 挂载为容器内 `/workspace/input`,`example_fs_nashp/output` 挂载为 `/workspace/output`,并默认向容器注入评测 L2 Cache 环境变量 `HB_DNN_USER_DEFINED_L2M_SIZES=6:6:6:6`(宿主机已设置该变量时使用宿主机的值)。
|
||||
|
||||
|
||||
### 交互式进入容器
|
||||
|
||||
镜像内置了 `hrt_model_exec` 等 BPU 工具,可以交互式进入容器手动调试模型。
|
||||
@ -268,15 +312,22 @@ bash docker_run_bayese_perf.sh
|
||||
**RDK S100(Nash-e / Nash-m)**
|
||||
|
||||
```bash
|
||||
cd bpu_model_perf_images
|
||||
bash docker_test_nashem.sh
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash test.sh
|
||||
```
|
||||
|
||||
**RDK X5(Bayes-e)**
|
||||
|
||||
```bash
|
||||
cd bpu_model_perf_images
|
||||
bash docker_test_bayese.sh
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash test.sh
|
||||
```
|
||||
|
||||
**RDK S600(Nash-p)**
|
||||
|
||||
```bash
|
||||
cd examples/bpu_model_perf/<nashem|bayese|nashp>
|
||||
bash test.sh
|
||||
```
|
||||
|
||||
进入容器后可直接使用 `hrt_model_exec`,例如:
|
||||
@ -387,11 +438,8 @@ CoreMark-PRO 包含以下 9 个工作负载:
|
||||
### 目录结构
|
||||
|
||||
```
|
||||
coremark_images/
|
||||
├── Dockerfile # 镜像构建文件
|
||||
├── docker_build.sh # 构建脚本
|
||||
├── docker_run.sh # 运行脚本
|
||||
├── docker_test.sh # 测试脚本
|
||||
examples/coremark/any/
|
||||
├── Dockerfile build.sh run.sh test.sh
|
||||
├── workspace/
|
||||
│ ├── coremark_perf.py # 性能测试主脚本
|
||||
│ └── entrypoint.sh # 容器入口脚本
|
||||
@ -407,7 +455,7 @@ coremark_images/
|
||||
**第一步:构建镜像**(只需构建一次)
|
||||
|
||||
```bash
|
||||
cd coremark_images
|
||||
cd examples/coremark/any
|
||||
bash docker_build.sh
|
||||
```
|
||||
|
||||
@ -525,3 +573,64 @@ Final CoreMark-PRO Score 7027.42
|
||||
| `benchmark_config` | 测试配置(workload 列表、线程数等) |
|
||||
| `results` | 每个 workload 在不同线程数下的性能数据 |
|
||||
| `coremark_pro_score` | 最终 CoreMark-PRO 综合得分 |
|
||||
|
||||
---
|
||||
|
||||
## /app 案例基础镜像(app_base)
|
||||
|
||||
### app_base 工具说明
|
||||
|
||||
覆盖板卡 `/app` 目录全部案例的基础镜像与运行框架。镜像内只包含通用开发运行环境(工具链、python、调试工具),板卡专属的库、工具、模型、案例全部由运行脚本从宿主机只读挂载进容器,保证容器环境与板上固件版本永远一致。
|
||||
|
||||
| 硬件平台 | BPU 架构 | 镜像 base | 镜像名称 |
|
||||
|----------|----------|----------|----------|
|
||||
| RDK S600 | Nash-p | ubuntu:24.04 | `app_base_nashp:v1.0.0` |
|
||||
| RDK S100 / RDK S100P | Nash-e / Nash-m | ubuntu:22.04 | `app_base_nashem:v1.0.0` |
|
||||
| RDK X5 / RDK X5 Module | Bayes-e | ubuntu:22.04 | `app_base_bayese:v1.0.0` |
|
||||
|
||||
镜像特点:
|
||||
|
||||
1. 案例精确可分开执行:BPU、GPU、VPU、VDSP/DSP、相机 VIO、IPC 外设、共享内存等硬件单元各有独立的设备透传集合,互不混入。
|
||||
2. 日常使用体验:容器内 PATH 已包含 `/usr/hobot/bin`(`hrt_model_exec`、`hbtop` 等命令直接可用),`LD_LIBRARY_PATH`、`CPATH`、`LIBRARY_PATH` 按板卡环境配置,`/app` 案例无需改 Makefile 即可在容器内编译运行,板卡 python 包(hbm_runtime 等)可直接 import。
|
||||
|
||||
### app_base 目录结构
|
||||
|
||||
```
|
||||
examples/
|
||||
├── common/app_base_common.sh # 公共库: 板型检测/挂载构建/按单元设备集
|
||||
├── app_base/any/ # 基础镜像 Dockerfile + build.sh + shell.sh + bench.sh
|
||||
│ └── output/<family>/ # 三板测试报告与基准产物
|
||||
├── <bpu|gpu|vpu|dsp|hbmem|mcu>/any/ # 硬件单元案例: Dockerfile + build.sh + run.sh + selftest.sh
|
||||
```
|
||||
|
||||
### app_base 使用方法
|
||||
|
||||
在目标板卡上构建(自动识别板型并选择 base):
|
||||
|
||||
```bash
|
||||
cd examples/app_base/any
|
||||
bash build.sh
|
||||
```
|
||||
|
||||
按硬件单元交互式进入容器:
|
||||
|
||||
```bash
|
||||
cd examples/app_base/any
|
||||
bash shell.sh bpu # BPU 推理
|
||||
bash shell.sh gpu # GPU (OpenCL/GLES)
|
||||
bash shell.sh vpu # 视频编解码
|
||||
bash shell.sh dsp # DSP (S600/S100 为 VDSP, X5 为 aDSP)
|
||||
bash shell.sh vio # 相机/ISP 通路
|
||||
bash shell.sh mcu # MCU 协处理器 (经 IPCF, i2c/spi/uart/gpio/can)
|
||||
bash shell.sh hbmem # 共享内存
|
||||
bash shell.sh all # 特权模式全量透传
|
||||
```
|
||||
|
||||
### app_base 基准对比
|
||||
|
||||
```bash
|
||||
cd examples/app_base/any
|
||||
bash bench.sh all # 或指定单元: bpu gpu vpu vdsp hbmem
|
||||
```
|
||||
|
||||
对 `/app` 下的代表性案例(BPU 推理、OpenCL、VPU 编码、VDSP、共享内存),在宿主机与容器内分别编译运行并对比。容器侧日志由容器经挂载直接写入 examples 目录(穿透),与宿主侧日志并列保存。测试结论见 `examples/app_base/any/output/<板型>/report.md`。
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -1 +0,0 @@
|
||||
Subproject commit 4832cc67b0926c7a80a4b7ce0ce00f4640ea6bec
|
||||
@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Build CoreMark-PRO benchmark Docker image
|
||||
|
||||
IMAGE_NAME="coremark_pro_rdk_arm"
|
||||
IMAGE_TAG="${1:-latest}"
|
||||
|
||||
echo "Building CoreMark-PRO benchmark image..."
|
||||
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
echo ""
|
||||
|
||||
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f Dockerfile .
|
||||
|
||||
echo ""
|
||||
echo "Build complete: ${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Run CoreMark-PRO CPU benchmark container
|
||||
# Output: /workspace/output/result.json (mounted from host)
|
||||
|
||||
IMAGE_NAME="coremark_pro_rdk_arm"
|
||||
IMAGE_TAG="latest"
|
||||
|
||||
# Default output directory on host
|
||||
HOST_OUTPUT_DIR="$(pwd)/example_fs/output"
|
||||
|
||||
# Allow override via environment variable
|
||||
if [ -n "$COREMARK_OUTPUT_DIR" ]; then
|
||||
HOST_OUTPUT_DIR="$COREMARK_OUTPUT_DIR"
|
||||
fi
|
||||
|
||||
mkdir -p "$HOST_OUTPUT_DIR"
|
||||
|
||||
echo "Running CoreMark-PRO benchmark..."
|
||||
echo "Output will be saved to: $HOST_OUTPUT_DIR/result.json"
|
||||
echo ""
|
||||
|
||||
docker run --rm \
|
||||
--name coremark_pro_rdk_arm \
|
||||
--privileged \
|
||||
-v "$HOST_OUTPUT_DIR":/workspace/output \
|
||||
${IMAGE_NAME}:${IMAGE_TAG}
|
||||
|
||||
echo ""
|
||||
echo "Benchmark complete. Results saved to: $HOST_OUTPUT_DIR/result.json"
|
||||
@ -1,633 +0,0 @@
|
||||
{
|
||||
"system_info": {
|
||||
"cpu": {
|
||||
"cpu_count": 8,
|
||||
"cpu_count_physical": 8,
|
||||
"cpu_freq_mhz": 1800.0,
|
||||
"cpu_percent": 2.0,
|
||||
"cpu_implementer": "0x41",
|
||||
"cpu_arch": "8",
|
||||
"cpu_model": "aarch64",
|
||||
"architecture": "aarch64"
|
||||
},
|
||||
"memory": {
|
||||
"total_mb": 5768,
|
||||
"available_mb": 2962,
|
||||
"percent_used": 48.6,
|
||||
"used_mb": 2805,
|
||||
"free_mb": 258
|
||||
},
|
||||
"system": {
|
||||
"hostname": "0f806e261978",
|
||||
"platform": "Linux-6.1.83-aarch64-with-glibc2.35",
|
||||
"system": "Linux",
|
||||
"release": "6.1.83",
|
||||
"version": "#4 SMP PREEMPT Fri Dec 19 10:54:38 CST 2025",
|
||||
"python_version": "3.10.12",
|
||||
"timestamp": "2026-03-20 11:59:37"
|
||||
}
|
||||
},
|
||||
"benchmark_config": {
|
||||
"workloads": [
|
||||
"cjpeg-rose7-preset",
|
||||
"core",
|
||||
"linear_alg-mid-100x100-sp",
|
||||
"loops-all-mid-10k-sp",
|
||||
"nnet_test",
|
||||
"parser-125k",
|
||||
"radix2-big-64k",
|
||||
"sha-test",
|
||||
"zip-test"
|
||||
],
|
||||
"thread_counts": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8
|
||||
],
|
||||
"max_threads": 8
|
||||
},
|
||||
"results": [
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 59.8802,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.1709287166595459,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 0.457038,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.191352128982544,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 24.7402,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.027066707611084,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 1.20875,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 41.36767315864563,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 1.71615,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 5.830807209014893,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 10.8696,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.15040898323059082,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 99.4827,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 10.061779260635376,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 106.383,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.10429215431213379,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 1,
|
||||
"iter_per_sec": 34.4828,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.7011659145355225,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 120.482,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.08684968948364258,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 0.913659,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.1916873455047607,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 49.554,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.0147795677185059,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 2.43013,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 20.578801155090332,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 3.43171,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.916877031326294,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 21.2766,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.15271854400634766,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 179.083,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 5.594027280807495,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 212.766,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.057444095611572266,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 2,
|
||||
"iter_per_sec": 66.6667,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.864583969116211,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 175.439,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.06096076965332031,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 1.37112,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.191770315170288,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 72.7802,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.6921648979187012,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 3.51519,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 14.228093385696411,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 4.29,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.3344318866729736,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 28.3019,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.16345930099487305,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 177.936,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 5.634125471115112,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 270.27,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.048152923583984375,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 3,
|
||||
"iter_per_sec": 100.0,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.8439626693725586,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 232.558,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.04668903350830078,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 1.81736,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.2041430473327637,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 95.057,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.5304605960845947,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 4.49035,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 11.139124155044556,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 5.71429,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.7527673244476318,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 30.303,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.19083714485168457,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 206.954,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 4.84836220741272,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 357.143,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.03871965408325195,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 4,
|
||||
"iter_per_sec": 129.032,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.823582410812378,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 294.118,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.03779315948486328,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 2.28311,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.194005012512207,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 123.762,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.4098236560821533,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 5.65803,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 8.841012477874756,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 8.56164,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.1719512939453125,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 34.0136,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.20575261116027832,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 218.436,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 4.595886468887329,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 526.316,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.029636859893798828,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 5,
|
||||
"iter_per_sec": 147.059,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.8295886516571045,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 312.5,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.035584449768066406,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 2.72975,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.201174020767212,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 137.363,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.3693256378173828,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 6.13497,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 8.154258012771606,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 8.56164,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.1719541549682617,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 32.7869,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.242201566696167,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 249.501,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 4.0301103591918945,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 526.316,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.029955625534057617,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 6,
|
||||
"iter_per_sec": 142.857,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.631044864654541,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 303.03,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.036682844161987305,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 3.01984,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.3219473361968994,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 150.602,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.33828091621398926,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 6.49266,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 7.704557657241821,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 8.30565,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.2081749439239502,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 27.7778,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.31223487854003906,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 278.164,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.6184468269348145,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 500.0,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.030409574508666992,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 7,
|
||||
"iter_per_sec": 152.174,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.6435928344726562,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "cjpeg-rose7-preset",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 370.37,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.031106233596801758,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "core",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 2.83386,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 2.8255538940429688,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "linear_alg-mid-100x100-sp",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 160.256,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.31850361824035645,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "loops-all-mid-10k-sp",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 7.03037,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 7.116137981414795,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "nnet_test",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 8.46024,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 1.1859660148620605,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "parser-125k",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 27.8746,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.34679079055786133,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "radix2-big-64k",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 277.469,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.6289494037628174,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "sha-test",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 526.316,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 0.03002643585205078,
|
||||
"raw_output": null
|
||||
},
|
||||
{
|
||||
"workload": "zip-test",
|
||||
"thread_num": 8,
|
||||
"iter_per_sec": 145.455,
|
||||
"returncode": 0,
|
||||
"elapsed_time_sec": 3.640843152999878,
|
||||
"raw_output": null
|
||||
}
|
||||
],
|
||||
"coremark_pro_score": 6507.155269914205
|
||||
}
|
||||
113
examples/README.md
Normal file
113
examples/README.md
Normal file
@ -0,0 +1,113 @@
|
||||
# examples/ 案例索引
|
||||
|
||||
第一级分类是案例, 第二级分类是平台: 纯 CPU 案例与三板共用 Dockerfile 的单元案例用 any,
|
||||
bpu_model_perf 按板拆 nashem / bayese / nashp。每个案例目录内统一为:
|
||||
一个 Dockerfile + build.sh + run.sh (+test.sh/selftest.sh) + output/(运行输出, 不入库)。
|
||||
|
||||
```
|
||||
examples/
|
||||
├── common/
|
||||
│ └── app_base_common.sh # 共享库: 板型检测/公共挂载/按硬件单元设备集
|
||||
├── coremark/any/ # CoreMark-PRO CPU 基准 (纯 CPU, 平台无关)
|
||||
│ │ # build.sh/run.sh/test.sh 三板均验证; 源码直接携带
|
||||
│ │ # 实测: S600=78305, S100=18497, X5=5379
|
||||
├── bpu_model_perf/
|
||||
│ ├── nashem/ # BPU 模型性能测试 (S100/S100P)
|
||||
│ ├── bayese/ # 同上 (X5)
|
||||
│ └── nashp/ # 同上 (S600, ubuntu:24.04 base)
|
||||
├── app_base/any/ # /app 全案例基础镜像 (板型自适应) + shell/bench 工具
|
||||
│ └── output/<family>/ # 三板测试报告与基准产物
|
||||
├── bpu/any/ # BPU 单元案例: mobilenetv2 分类 (自测判 top1=zebra)
|
||||
├── gpu/any/ # GPU 单元案例: OpenCL 矩阵乘
|
||||
├── vpu/any/ # VPU+JPU 单元案例: sample_codec 双路径 (H264 走 VPU, JPEG 走 JPU)
|
||||
├── dsp/any/ # DSP 单元案例: S600/S100 为 VDSP(vdsp_sample), X5 为 aDSP(sample_dsp)
|
||||
├── hbmem/any/ # 共享内存单元案例: cached/uncached memset
|
||||
└── mcu/any/ # MCU 单元案例: ipcbox_runcmd 经 IPCF 与 MCU 收发
|
||||
├── firmware/ # MCU 固件 (BSP 版本记录见 firmware/README.md)
|
||||
└── install_mcu_runtime.sh# MCU 固件装载 + 开机自启服务
|
||||
```
|
||||
|
||||
## 用法
|
||||
|
||||
每个案例在目标板上执行:
|
||||
|
||||
```bash
|
||||
cd examples/<案例>/<平台>
|
||||
bash build.sh # 构建镜像 (案例编译进镜像)
|
||||
bash run.sh # 运行/自测 (精确 --device 透传该硬件单元, 日志写 output/)
|
||||
```
|
||||
|
||||
app_base 基础镜像需先构建 (单元案例的构建层):
|
||||
|
||||
```bash
|
||||
cd examples/app_base/any && bash build.sh
|
||||
bash shell.sh bpu # 交互式进入容器 (按单元透传设备)
|
||||
bash bench.sh all # 宿主机 vs 容器基准对比
|
||||
```
|
||||
|
||||
## 硬件单元与设备透传
|
||||
|
||||
单元划分以硬件对端命名。IPCF (跨核通信框架, 共享内存 + 邮箱中断 + /dev/ipcdrv)
|
||||
是互连底座而非计算单元: VDSP 走 IPCF ins22/42, BPU 有 rpmsg_bpu 通道, timesync/CAN
|
||||
亦经 IPCF。ipcbox 案例的单元因此为 MCU, IPCF 只是到达它的总线。
|
||||
|
||||
| 单元 | 透传设备 |
|
||||
|---|---|
|
||||
| bpu | /dev/bpu, /dev/bpu_core0-7, /dev/ion |
|
||||
| gpu | /dev/mali0 或 /dev/galcore, /dev/dri |
|
||||
| vpu(+jpu) | /dev/vpu(1,2), /dev/jpu(1,2), /dev/codec0_cap, /dev/codec0_src, /dev/ion |
|
||||
| dsp | /dev/vdsp0(1), /dev/dcore0/1_rpmsg_op, /dev/dcore0/1_device_op, /dev/dsp, /dev/ipcdrv, /dev/ion |
|
||||
| vio | /dev/i2c-*, /dev/vin*, /dev/isp*, /dev/pym*, /dev/stitch*, /dev/gdc*, /dev/ynr*, /dev/idu*, /dev/port_*, /dev/deserial_*, /dev/sensor_ctrl, /dev/mipi*, /dev/video*, /dev/media*, /dev/flow, /dev/ion |
|
||||
| mcu | /dev/ipcdrv, /dev/i2c-*, /dev/spidev*, /dev/ttyS*, /dev/gpiochip*, /dev/hrtc0, /dev/pps*, /dev/ptp* |
|
||||
| hbmem | /dev/ion, /dev/hbmem* |
|
||||
| all | --privileged 全量 |
|
||||
|
||||
## 三板实测结论
|
||||
|
||||
| 案例 | S600 | S100 | X5 |
|
||||
|---|---|---|---|
|
||||
| bpu | PASS | PASS | PASS (pydev 特例) |
|
||||
| gpu | PASS | PASS | PASS |
|
||||
| vpu+jpu | PASS | PASS | PASS |
|
||||
| dsp | PASS (VDSP) | PASS (VDSP) | 不测 (按约定) |
|
||||
| hbmem | PASS | PASS | PASS |
|
||||
| mcu | PASS (ADC 回显) | PASS (ADC 回显) | 不适用 |
|
||||
|
||||
容器 vs 宿主机性能差异均在运行噪声内 (无损调用): 字符设备直通、宿主原库挂载、
|
||||
零虚拟化层。完整报告见 app_base/any/output/<family>/report.md。
|
||||
|
||||
## 公共镜像仓库 (已推送并实测验证)
|
||||
|
||||
以下 25 个镜像已全部推送至 BCR 公共仓库 `ccr-29eug8s3-pub.cnc.bj.baidubce.com/rlark/`,
|
||||
均经过三板真实构建与运行验证。拉取时直接使用完整地址即可,无需登录 (public 仓库)。
|
||||
|
||||
### 基础镜像
|
||||
|
||||
| 板 | 公共地址 |
|
||||
|---|---|
|
||||
| S600 | ccr-29eug8s3-pub.cnc.bj.baidubce.com/rlark/app_base_nashp:261020_113638 |
|
||||
| S100 | ccr-29eug8s3-pub.cnc.bj.baidubce.com/rlark/app_base_nashem:261020_114116 |
|
||||
| X5 | ccr-29eug8s3-pub.cnc.bj.baidubce.com/rlark/app_base_bayese:261020_114308 |
|
||||
|
||||
### 硬件单元案例镜像
|
||||
|
||||
| 单元 | S600 | S100 | X5 |
|
||||
|---|---|---|---|
|
||||
| bpu | .../rlark/case_bpu_nashp:261020_113827 | .../rlark/case_bpu_nashem:261020_114139 | .../rlark/case_bpu_bayese:261020_114330 |
|
||||
| gpu | .../rlark/case_gpu_nashp:261020_113920 | .../rlark/case_gpu_nashem:261020_114147 | .../rlark/case_gpu_bayese:261020_114339 |
|
||||
| vpu(+jpu) | .../rlark/case_vpu_nashp:261020_113931 | .../rlark/case_vpu_nashem:261020_114201 | .../rlark/case_vpu_bayese:261020_114415 |
|
||||
| dsp | .../rlark/case_dsp_nashp:261020_113946 | .../rlark/case_dsp_nashem:261020_114218 | 不适用 |
|
||||
| hbmem | .../rlark/case_hbmem_nashp:261020_113952 | .../rlark/case_hbmem_nashem:261020_114225 | .../rlark/case_hbmem_bayese:261020_114430 |
|
||||
| mcu | .../rlark/case_mcu_nashp:261020_114000 | .../rlark/case_mcu_nashem:261020_114233 | 不适用 |
|
||||
|
||||
表中 `...` 为 `ccr-29eug8s3-pub.cnc.bj.baidubce.com` 前缀。
|
||||
|
||||
### 独立测试案例镜像
|
||||
|
||||
| 案例 | S600 | S100 | X5 |
|
||||
|---|---|---|---|
|
||||
| bpu_model_perf | .../rlark/hrt_perf_nashp:261020_114006 | .../rlark/hrt_perf_nashem:261020_114239 | .../rlark/hrt_perf_bayese:261020_114435 |
|
||||
| coremark | .../rlark/coremark_pro_rdk_arm:261020_114037 | .../rlark/coremark_pro_rdk_arm:261020_114249 | .../rlark/coremark_pro_rdk_arm:261020_114445 |
|
||||
|
||||
注意: coremark 三板共用同一仓库名但 tag 不同 (每次构建独立生成时间戳)。
|
||||
各镜像的运行方式见各案例目录内的 run.sh / test.sh。
|
||||
100
examples/app_base/any/Dockerfile
Normal file
100
examples/app_base/any/Dockerfile
Normal file
@ -0,0 +1,100 @@
|
||||
# /app 案例基础镜像 (三板共用, 通过 --build-arg 区分 base)
|
||||
# nashp (RDK S600, Nash-p): --build-arg BASE_IMAGE=ubuntu:24.04
|
||||
# nashem (RDK S100, Nash-e/m): --build-arg BASE_IMAGE=ubuntu:22.04
|
||||
# bayese (RDK X5, Bayes-e): --build-arg BASE_IMAGE=ubuntu:22.04
|
||||
#
|
||||
# 设计: 镜像内只放"通用开发运行环境"(工具链/python/调试工具),
|
||||
# 板卡专属的库/工具/模型/案例全部由运行脚本从宿主机 bind-mount 进来,
|
||||
# 保证容器内环境与板上固件版本永远一致。
|
||||
# base 必须与板卡系统同代: nashp 板是 Ubuntu 24.04 (glibc 2.39),
|
||||
# nashem/bayese 板是 Ubuntu 22.04 (glibc 2.35), 不可混用。
|
||||
ARG BASE_IMAGE=ubuntu:24.04
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# apt 源切换到国内镜像 (arm64 base 的源在 ports.ubuntu.com, 部分板卡网络下
|
||||
# 下载速度极慢, 实测 tuna 的 ubuntu-ports 镜像快约 80 倍)
|
||||
RUN sed -i 's|ports.ubuntu.com/ubuntu-ports|mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' /etc/apt/sources.list 2>/dev/null || true; \
|
||||
sed -i 's|ports.ubuntu.com/ubuntu-ports|mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' /etc/apt/sources.list.d/*.sources 2>/dev/null || true
|
||||
|
||||
# ============================================================
|
||||
# 工具链与常用工具 (案例均为源码形态, 需要板上编译)
|
||||
# ============================================================
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
pkg-config \
|
||||
libgflags-dev \
|
||||
libfmt-dev \
|
||||
gdb \
|
||||
strace \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-venv \
|
||||
git \
|
||||
wget \
|
||||
curl \
|
||||
vim \
|
||||
tmux \
|
||||
less \
|
||||
file \
|
||||
bzip2 \
|
||||
xz-utils \
|
||||
iputils-ping \
|
||||
net-tools \
|
||||
i2c-tools \
|
||||
libsndfile1-dev \
|
||||
libsamplerate0-dev \
|
||||
openssh-server \
|
||||
locales \
|
||||
&& mkdir -p /var/run/sshd \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 配置中文 locale(防止终端中文乱码)
|
||||
RUN locale-gen zh_CN.UTF-8 && update-locale LANG=zh_CN.UTF-8
|
||||
|
||||
# ============================================================
|
||||
# 板卡环境粘合层
|
||||
# 以下 ENV 指向的路径由运行脚本 bind-mount 提供:
|
||||
# /usr/hobot 板卡工具+库+头文件+sensor+固件 (宿主 /usr/hobot)
|
||||
# /app 全部案例源码与资源 (宿主 /app)
|
||||
# /opt/hobot /opt/tros 模型与 tros
|
||||
# /host_lib/usr_lib 宿主 /usr/lib (libspcdev/libdnn 等直放库)
|
||||
# /host_inc/usr_include 宿主 /usr/include (sp_*.h, dnn/ 等头文件, 经 CPATH 生效)
|
||||
# /usr/local/lib/python3.X/dist-packages 板卡 python 包 (hbm_runtime 等)
|
||||
# ============================================================
|
||||
|
||||
# 板卡命令优先 (hrt_model_exec / hrt_ucp_monitor / hbtop / hrut_* ...)
|
||||
ENV PATH=/usr/hobot/bin:/app/bin:${PATH}
|
||||
|
||||
# 库搜索路径: 板卡库优先, 其次宿主系统库, 最后容器自带
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
|
||||
# 编译头文件搜索 (gcc 的 CPATH, 等效 -I, 不遮蔽容器系统头文件;
|
||||
# aarch64 多架构头文件如 libavcodec/ 在 /usr/include/aarch64-linux-gnu 下;
|
||||
# cjson/opencv4 为板上 Makefile 常用 -I 子目录)
|
||||
ENV CPATH=/usr/hobot/include:/host_inc/usr_include:/host_inc/usr_include/aarch64-linux-gnu:/host_inc/usr_include/cjson:/host_inc/usr_include/opencv4
|
||||
|
||||
# 链接库搜索 (ld 的 LIBRARY_PATH, 等效 -L, 使无 -L/usr/lib 的
|
||||
# "-lspcdev" 等也能找到宿主 /usr/lib 下的直放库)
|
||||
ENV LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu
|
||||
|
||||
ENV HOBOT_ROOTFS_DIR=/usr/hobot
|
||||
ENV GST_PLUGIN_PATH=/usr/hobot/lib/gst-plugins
|
||||
ENV LANG=zh_CN.UTF-8
|
||||
ENV LC_ALL=zh_CN.UTF-8
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# SSH 调试入口 (root:root, 与 bpu_model_perf_images 保持一致)
|
||||
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
|
||||
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
|
||||
&& ssh-keygen -A \
|
||||
&& echo 'root:root' | chpasswd
|
||||
|
||||
# 基准测试与报告的工作目录 (运行时挂载 examples 目录进来)
|
||||
RUN mkdir -p /workspace
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
# 不设 ENTRYPOINT: 由 docker_app_shell.sh / docker_app_bench.sh 决定入口
|
||||
227
examples/app_base/any/bench.sh
Executable file
227
examples/app_base/any/bench.sh
Executable file
@ -0,0 +1,227 @@
|
||||
#!/bin/bash
|
||||
# app_base 容器 vs 宿主机 基准对比脚本
|
||||
# 对 /app 下的代表性案例, 在宿主机与容器内分别编译运行, 对比性能与行为
|
||||
#
|
||||
# 用法: bash bench.sh [bpu|gpu|vpu|dsp|hbmem|all]
|
||||
# 默认 all (按板型自动跳过不存在的单元)
|
||||
#
|
||||
# 输出 (本目录 output/<family>/):
|
||||
# artifacts/host/<case>.log 宿主运行原始日志
|
||||
# artifacts/container/<case>.log 容器运行原始日志(经挂载穿透落到本目录)
|
||||
# bench_latest.json 机器可读结果
|
||||
# 终端对比表
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
EX_DIR="$SCRIPT_DIR/output/$FAMILY"
|
||||
ART_H="$EX_DIR/artifacts/host"
|
||||
ART_C="$EX_DIR/artifacts/container"
|
||||
mkdir -p "$ART_H" "$ART_C"
|
||||
|
||||
# BPU 评测统一 L2 Cache 配置 (宿主已设置则沿用)
|
||||
export HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}"
|
||||
|
||||
RESULTS=() # 每行: case|metric|host|container|unit
|
||||
|
||||
add_result() { RESULTS+=("$1|$2|$3|$4|$5"); }
|
||||
|
||||
# 在宿主机跑 (日志写入 $ART_H)
|
||||
# 注入与容器镜像一致的编译链接环境 (LIBRARY_PATH/CPATH),
|
||||
# 否则 X5 板上 -lalog/-lmultimedia 等链接失败
|
||||
host_run() {
|
||||
local log="$1"; shift
|
||||
bash -c "
|
||||
export LIBRARY_PATH=/usr/hobot/lib:/usr/lib:/usr/lib/aarch64-linux-gnu
|
||||
export CPATH=/usr/hobot/include:/usr/include:/usr/include/aarch64-linux-gnu:/usr/include/cjson:/usr/include/opencv4
|
||||
$*" > "$ART_H/$log" 2>&1 || true
|
||||
tail -5 "$ART_H/$log"
|
||||
}
|
||||
|
||||
# 在容器内跑 (容器内编译+运行, 日志穿透挂载写入 $ART_C)
|
||||
ctr_run() {
|
||||
local unit="$1"; local log="$2"; local cmd="$3"
|
||||
local dev; dev="$(build_device_args "$unit")"
|
||||
local mnt; mnt="$(build_common_mount_args)"
|
||||
local inner="cd /workspace && { $cmd ; } > /workspace/artifacts/container/$log 2>&1"
|
||||
# shellcheck disable=SC2086 # $mnt/$dev 需按词拆分
|
||||
timeout 420 docker run --rm --name "app-bench-$unit" \
|
||||
$mnt $dev \
|
||||
-v "$EX_DIR":/workspace \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES \
|
||||
"$APP_BASE_TAG" bash -c "$inner" || true
|
||||
tail -5 "$ART_C/$log"
|
||||
}
|
||||
|
||||
# 取日志中最后一个匹配行的最后一个数字 (无匹配返回空, 不触发 set -e)
|
||||
last_num() { grep -oE "$2" "$1" 2>/dev/null | tail -1 | grep -oE '[0-9]+\.?[0-9]*' | tail -1 || true; }
|
||||
|
||||
# ============================================================
|
||||
# BPU: hrt_model_exec perf (1线程与4线程 FPS)
|
||||
# ============================================================
|
||||
bench_bpu() {
|
||||
echo "--- [bpu] hrt_model_exec perf ---"
|
||||
local model
|
||||
model=$(ls /opt/hobot/model/*/basic/yolo11n* 2>/dev/null | head -1)
|
||||
if [ -z "$model" ]; then
|
||||
model=$(ls /opt/hobot/model/*/basic/*.hbm /opt/hobot/model/*/basic/*.bin 2>/dev/null | head -1)
|
||||
fi
|
||||
if [ -z "$model" ]; then echo "[skip] 无模型"; return; fi
|
||||
echo "model: $model"
|
||||
|
||||
host_run bpu_t1.log "hrt_model_exec perf --model_file '$model' --thread_num 1 --frame_count 200"
|
||||
host_run bpu_t4.log "hrt_model_exec perf --model_file '$model' --thread_num 4 --frame_count 200"
|
||||
ctr_run bpu "bpu_t1.log" "hrt_model_exec perf --model_file '$model' --thread_num 1 --frame_count 200"
|
||||
ctr_run bpu "bpu_t4.log" "hrt_model_exec perf --model_file '$model' --thread_num 4 --frame_count 200"
|
||||
|
||||
local h1 c1 h4 c4
|
||||
h1=$(last_num "$ART_H/bpu_t1.log" 'Frame[[:space:]]+rate[[:space:]]+is:[[:space:]]+[0-9.]+')
|
||||
c1=$(last_num "$ART_C/bpu_t1.log" 'Frame[[:space:]]+rate[[:space:]]+is:[[:space:]]+[0-9.]+')
|
||||
h4=$(last_num "$ART_H/bpu_t4.log" 'Frame[[:space:]]+rate[[:space:]]+is:[[:space:]]+[0-9.]+')
|
||||
c4=$(last_num "$ART_C/bpu_t4.log" 'Frame[[:space:]]+rate[[:space:]]+is:[[:space:]]+[0-9.]+')
|
||||
add_result bpu "perf_t1_fps" "${h1:-FAIL}" "${c1:-FAIL}" "FPS"
|
||||
add_result bpu "perf_t4_fps" "${h4:-FAIL}" "${c4:-FAIL}" "FPS"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# GPU: sample_gpu_3d/cl matrix_multiply (OpenCL/CPU 耗时 + 编译耗时)
|
||||
# ============================================================
|
||||
bench_gpu() {
|
||||
echo "--- [gpu] OpenCL matrix_multiply ---"
|
||||
[ -e /dev/mali0 ] || [ -e /dev/galcore ] || { echo "[skip] 无 GPU 设备"; return; }
|
||||
[ -d /app/multimedia_samples/sample_gpu_3d/cl/sample_matrix_multiply ] || { echo "[skip] 无案例"; return; }
|
||||
|
||||
# X5 的 Makefile include ../../../Makefile.in 且需 HR_BUILD_OUTPUT_DIR,
|
||||
# 统一整树拷贝到 /tmp/bench_mm 再进案例目录构建
|
||||
local script='
|
||||
export HR_BUILD_OUTPUT_DIR=/tmp/hr_out CROSS_COMPILE=/usr/bin/; mkdir -p /tmp/hr_out
|
||||
rm -rf /tmp/bench_mm && cp -r /app/multimedia_samples /tmp/bench_mm
|
||||
cd /tmp/bench_mm/sample_gpu_3d/cl/sample_matrix_multiply
|
||||
t0=$(date +%s.%N); make >/dev/null 2>&1; t1=$(date +%s.%N)
|
||||
echo "build_sec $(echo "$t1 $t0" | awk "{printf \"%.2f\", \$1-\$2}")"
|
||||
BIN=$(find . /tmp/hr_out -maxdepth 4 -type f -name matrix_multiply -perm -u+x 2>/dev/null | head -1)
|
||||
[ -n "$BIN" ] && timeout 30 "$BIN" 2>/dev/null'
|
||||
host_run gpu.log "$script"
|
||||
ctr_run gpu "gpu.log" "$script"
|
||||
|
||||
add_result gpu build_sec "$(last_num "$ART_H/gpu.log" 'build_sec [0-9.]+')" "$(last_num "$ART_C/gpu.log" 'build_sec [0-9.]+')" "s"
|
||||
add_result gpu opencl_sec "$(last_num "$ART_H/gpu.log" 'OpenCL execution time: [0-9.]+')" "$(last_num "$ART_C/gpu.log" 'OpenCL execution time: [0-9.]+')" "s"
|
||||
add_result gpu cpu_ref_sec "$(last_num "$ART_H/gpu.log" 'CPU execution time: [0-9.]+')" "$(last_num "$ART_C/gpu.log" 'CPU execution time: [0-9.]+')" "s"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# VPU+JPU: sample_codec 编码 15s 帧数
|
||||
# ============================================================
|
||||
bench_vpu() {
|
||||
echo "--- [vpu] sample_codec encode ---"
|
||||
[ -e /dev/vpu ] || { echo "[skip] 无 VPU 设备"; return; }
|
||||
[ -d /app/multimedia_samples/sample_codec ] || { echo "[skip] 无案例"; return; }
|
||||
|
||||
local build='export HR_BUILD_OUTPUT_DIR=/tmp/hr_out CROSS_COMPILE=/usr/bin/; mkdir -p /tmp/hr_out; rm -rf /tmp/bench_mm && cp -r /app/multimedia_samples /tmp/bench_mm && cd /tmp/bench_mm/sample_codec && make >/dev/null 2>&1'
|
||||
host_run vpu.log "$build; cd /tmp/bench_mm/sample_codec && timeout 15 ./sample_codec"
|
||||
ctr_run vpu "vpu.log" "$build; cd /tmp/bench_mm/sample_codec && timeout 15 ./sample_codec"
|
||||
|
||||
local hf cf
|
||||
hf=$(last_num "$ART_H/vpu.log" 'frame=[[:space:]]*[0-9]+')
|
||||
cf=$(last_num "$ART_C/vpu.log" 'frame=[[:space:]]*[0-9]+')
|
||||
# 15 秒窗口 -> fps
|
||||
hf=${hf:+$(awk "BEGIN{printf \"%.1f\", $hf/15}")}
|
||||
cf=${cf:+$(awk "BEGIN{printf \"%.1f\", $cf/15}")}
|
||||
add_result vpu encode_fps "${hf:-FAIL}" "${cf:-FAIL}" "FPS(15s)"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# DSP: vdsp_sample (S600/S100; 行为一致性记录)
|
||||
# ============================================================
|
||||
bench_dsp() {
|
||||
echo "--- [dsp] vdsp_sample ---"
|
||||
ls /dev/vdsp* >/dev/null 2>&1 || { echo "[skip] 无 VDSP 设备"; return; }
|
||||
[ -d /app/vdsp_demo/vdsp_sample ] || { echo "[skip] 无案例"; return; }
|
||||
|
||||
local build='rm -rf /tmp/bench_vdsp && cp -r /app/vdsp_demo/vdsp_sample /tmp/bench_vdsp && cd /tmp/bench_vdsp && make >/dev/null 2>&1'
|
||||
host_run dsp.log "$build; cd /tmp/bench_vdsp && timeout 60 ./vdsp_sample -d 0 -p res/q8sample -t 0"
|
||||
ctr_run dsp "dsp.log" "$build; cd /tmp/bench_vdsp && timeout 60 ./vdsp_sample -d 0 -p res/q8sample -t 0"
|
||||
|
||||
local hs cs
|
||||
hs=$(grep -cE 'ERROR|error' "$ART_H/dsp.log" 2>/dev/null || true); hs=${hs:-0}
|
||||
cs=$(grep -cE 'ERROR|error' "$ART_C/dsp.log" 2>/dev/null || true); cs=${cs:-0}
|
||||
add_result dsp run_behavior "err_lines=$hs" "err_lines=$cs" "parity"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# hbmem: 共享内存 memset 耗时 (cached/uncached)
|
||||
# ============================================================
|
||||
bench_hbmem() {
|
||||
echo "--- [hbmem] libhbmem_sample ---"
|
||||
[ -e /dev/ion ] || { echo "[skip] 无 ION 设备"; return; }
|
||||
|
||||
if [ -d /app/communication_demo/hbmem_demo/sample_hbmem ]; then
|
||||
local build='rm -rf /tmp/bench_hbmem && cp -r /app/communication_demo/hbmem_demo/sample_hbmem /tmp/bench_hbmem && cd /tmp/bench_hbmem && make >/dev/null 2>&1'
|
||||
host_run hbmem.log "$build; cd /tmp/bench_hbmem && timeout 30 ./libhbmem_sample"
|
||||
ctr_run hbmem "hbmem.log" "$build; cd /tmp/bench_hbmem && timeout 30 ./libhbmem_sample"
|
||||
elif [ -d /app/multimedia_samples/sample_hbmem ]; then
|
||||
local build='export HR_BUILD_OUTPUT_DIR=/tmp/hr_out CROSS_COMPILE=/usr/bin/; mkdir -p /tmp/hr_out; rm -rf /tmp/bench_mm && cp -r /app/multimedia_samples /tmp/bench_mm && cd /tmp/bench_mm/sample_hbmem && make >/dev/null 2>&1'
|
||||
local run='BIN=$(find /tmp/bench_mm/sample_hbmem /tmp/hr_out -maxdepth 4 -type f -name "sample_hbmem*" -perm -u+x 2>/dev/null | head -1); [ -n "$BIN" ] && timeout 30 "$BIN" -m 2'
|
||||
host_run hbmem.log "$build; $run"
|
||||
ctr_run hbmem "hbmem.log" "$build; $run"
|
||||
else
|
||||
echo "[skip] 无案例"; return
|
||||
fi
|
||||
|
||||
add_result hbmem memset_uncached_us "$(last_num "$ART_H/hbmem.log" 'memset uncached buf\(size:[0-9]+\) use time: [0-9]+')" "$(last_num "$ART_C/hbmem.log" 'memset uncached buf\(size:[0-9]+\) use time: [0-9]+')" "us(4MB)"
|
||||
add_result hbmem memset_cached_us "$(last_num "$ART_H/hbmem.log" 'memset cached buf\(size:[0-9]+\) use time: [0-9]+')" "$(last_num "$ART_C/hbmem.log" 'memset cached buf\(size:[0-9]+\) use time: [0-9]+')" "us(4MB)"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# 汇总输出
|
||||
# ============================================================
|
||||
print_summary() {
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
echo " 基准对比: 宿主机 vs app_base 容器 ($FAMILY)"
|
||||
echo " 模型/案例均来自 /app 与 /opt/hobot/model"
|
||||
echo "============================================================"
|
||||
printf "%-8s %-20s %14s %14s %10s\n" "case" "metric" "host" "container" "unit"
|
||||
printf "%-8s %-20s %14s %14s %10s\n" "----" "------" "----" "---------" "----"
|
||||
local line f m h c u
|
||||
for line in "${RESULTS[@]}"; do
|
||||
IFS='|' read -r f m h c u <<< "$line"
|
||||
printf "%-8s %-20s %14s %14s %10s\n" "$f" "$m" "$h" "$c" "$u"
|
||||
done
|
||||
|
||||
local json="$EX_DIR/bench_latest.json"
|
||||
{
|
||||
echo "{"
|
||||
echo " \"family\": \"$FAMILY\","
|
||||
echo " \"image\": \"$APP_BASE_TAG\","
|
||||
echo " \"date\": \"$(date '+%Y-%m-%d %H:%M:%S')\","
|
||||
echo " \"l2_cache\": \"$HB_DNN_USER_DEFINED_L2M_SIZES\","
|
||||
echo " \"kernel\": \"$(uname -r)\","
|
||||
echo " \"results\": ["
|
||||
local first=1
|
||||
for line in "${RESULTS[@]}"; do
|
||||
IFS='|' read -r f m h c u <<< "$line"
|
||||
[ $first -eq 0 ] && echo ","
|
||||
first=0
|
||||
printf ' {"case":"%s","metric":"%s","host":"%s","container":"%s","unit":"%s"}' "$f" "$m" "$h" "$c" "$u"
|
||||
done
|
||||
echo ""
|
||||
echo " ]"
|
||||
echo "}"
|
||||
} > "$json"
|
||||
echo ""
|
||||
echo "[OK] 原始日志: $EX_DIR/artifacts/{host,container}/"
|
||||
echo "[OK] 机器可读: $json"
|
||||
}
|
||||
|
||||
UNITS="${1:-all}"
|
||||
echo "板型: $FAMILY 镜像: $APP_BASE_TAG 单元: $UNITS"
|
||||
for u in $UNITS; do
|
||||
case "$u" in
|
||||
all) bench_bpu; bench_gpu; bench_vpu; bench_dsp; bench_hbmem ;;
|
||||
bpu|gpu|vpu|dsp|hbmem) "bench_$u" ;;
|
||||
*) echo "[ERROR] 未知单元 $u"; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
print_summary
|
||||
17
examples/app_base/any/build.sh
Executable file
17
examples/app_base/any/build.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# app_base 基础镜像构建 (三板共用, 板型自动识别选择 base)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh" 2>/dev/null || true
|
||||
FAMILY="$(detect_family)"
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) BASE_IMAGE="ubuntu:24.04" ;;
|
||||
*) BASE_IMAGE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
TAG="$(date +%y%m%d_%H%M%S)"
|
||||
APP_BASE_TAG="app_base_${FAMILY}:${TAG}"
|
||||
echo "[INFO] 板型: $FAMILY, base: $BASE_IMAGE, 目标镜像: $APP_BASE_TAG"
|
||||
docker build --build-arg BASE_IMAGE="$BASE_IMAGE" -t "$APP_BASE_TAG" "$SCRIPT_DIR"
|
||||
echo "[OK] 构建完成: $APP_BASE_TAG"
|
||||
33
examples/app_base/any/shell.sh
Executable file
33
examples/app_base/any/shell.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# 交互式进入 app_base 容器, 按硬件单元精确挂载设备
|
||||
# 用法: bash shell.sh [bpu|gpu|vpu|dsp|vio|mcu|hbmem|all]
|
||||
# 默认 bpu; all 为 --privileged 全量透传
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
UNIT="${1:-bpu}"
|
||||
UNIT_CN="$(unit_cn_name "$UNIT")"
|
||||
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args "$UNIT")"
|
||||
|
||||
echo "============================================================"
|
||||
echo " app_base 交互容器"
|
||||
echo " 板型: $FAMILY 镜像: $APP_BASE_TAG"
|
||||
echo " 单元: $UNIT ($UNIT_CN)"
|
||||
echo " 设备: $DEVICE_ARGS"
|
||||
echo " 容器内 /app /usr/hobot /opt/hobot 均为宿主只读挂载,"
|
||||
echo " PATH/LD_LIBRARY_PATH/CPATH 已按板卡环境配置。"
|
||||
echo "============================================================"
|
||||
|
||||
# shellcheck disable=SC2086 # 挂载/设备参数需按词拆分
|
||||
docker run -it --rm \
|
||||
--name "app-base-$UNIT" \
|
||||
$MOUNT_ARGS \
|
||||
$DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
-e ROS_DOMAIN_ID="${ROS_DOMAIN_ID:-0}" \
|
||||
"$APP_BASE_TAG" \
|
||||
bash
|
||||
50
examples/bpu/any/Dockerfile
Normal file
50
examples/bpu/any/Dockerfile
Normal file
@ -0,0 +1,50 @@
|
||||
# BPU 单元案例镜像: 图像分类样例 (cdev_demo/bpu, 单一硬件: BPU)
|
||||
# S600/S100: classification_sample/mobilenetv2 (CMake+gflags)
|
||||
# X5: cdev_demo/bpu (make, 输出 bin/sample)
|
||||
# 构建: build_case.sh bpu ; 运行: run_case.sh bpu
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY syslib /usr/lib/aarch64-linux-gnu
|
||||
COPY sysinc /usr/include
|
||||
COPY src /src
|
||||
COPY utils /utils
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
# S600/S100 为 CMake 工程; X5 为 src/ 下 make
|
||||
# --allow-shlib-undefined: 链接期放行 opencv 等共享库的传递符号,
|
||||
# 运行期由宿主挂载的完整库集解析 (自测入口会实际运行验证)
|
||||
RUN mkdir -p /tmp/out && cd /src && if [ -f CMakeLists.txt ]; then \
|
||||
mkdir -p build && cd build && \
|
||||
cmake .. -DCMAKE_EXE_LINKER_FLAGS="-Wl,--allow-shlib-undefined" >/dev/null && make; \
|
||||
else \
|
||||
cd src && make; \
|
||||
fi
|
||||
|
||||
# 按 SONAME 归一化导出 opencv/lapack/blas/tbb 真实文件到 /rl
|
||||
# (板上这些库存在悬空或 alternatives 绝对路径符号链接, 容器目录扫描不可靠;
|
||||
# 导出为以 SONAME 命名的真实文件, 运行镜像直接烤入, 跨版本通用)
|
||||
RUN mkdir /rl && cd /usr/lib/aarch64-linux-gnu && \
|
||||
for f in libopencv_*.so.* liblapack.so.* libblas.so.* libtbb.so.* libtbbmalloc.so.*; do \
|
||||
[ -f "$f" ] && [ ! -L "$f" ] || continue; \
|
||||
s=$(readelf -d "$f" 2>/dev/null | sed -n 's/.*soname: *\[\(.*\)\]/\1/p'); \
|
||||
[ -n "$s" ] && cp -L "$f" "/rl/$s"; \
|
||||
done; true
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /rl /usr/lib/aarch64-linux-gnu/
|
||||
COPY --from=builder /src /opt/test
|
||||
# X5 的 make 把产物输出到 HR_BUILD_OUTPUT_DIR, 一并拷入
|
||||
COPY --from=builder /tmp/out /opt/test/out
|
||||
# X5 的 BPU 单元自测用 pydev 静态分类样例
|
||||
COPY py_case /opt/test/py_case
|
||||
# 直放于宿主 /usr/lib 根目录的库 (脚本硬编码路径引用), 烤入运行镜像
|
||||
COPY usrlib_root /usr/lib/
|
||||
COPY bpu_model.hbm /opt/test/model.hbm
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
125
examples/bpu/any/build.sh
Executable file
125
examples/bpu/any/build.sh
Executable file
@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
# bpu 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_bpu_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
local bpu_src=""
|
||||
if [ -d /app/cdev_demo/bpu/classification_sample/mobilenetv2 ]; then
|
||||
bpu_src=/app/cdev_demo/bpu/classification_sample/mobilenetv2
|
||||
elif ls -d /app/cdev_demo/bpu/*classification_sample/*mobilenetv2 >/dev/null 2>&1; then
|
||||
bpu_src=$(ls -d /app/cdev_demo/bpu/*classification_sample/*mobilenetv2 | head -1)
|
||||
fi
|
||||
if [ -n "$bpu_src" ]; then
|
||||
cp -a "$bpu_src/." "$CTX/src/"
|
||||
cp_r /app/cdev_demo/bpu/utils "$CTX/"
|
||||
# OpenCV 链接库(全模块, cmake 校验所有 target) + cmake 配置 + 头文件
|
||||
mkdir -p "$CTX/syslib/cmake" "$CTX/sysinc"
|
||||
cp_r /usr/lib/aarch64-linux-gnu/libopencv_*.so* "$CTX/syslib/"
|
||||
# 修复板上 opencv 打包缺陷: 部分符号链接指向自身(悬空), 按 ELF SONAME 重建
|
||||
find "$CTX/syslib" -xtype l -delete 2>/dev/null
|
||||
local _real _son
|
||||
for _real in "$CTX/syslib"/libopencv_*.so.*; do
|
||||
[ -f "$_real" ] && [ ! -L "$_real" ] || continue
|
||||
_son="$(readelf -d "$_real" 2>/dev/null | sed -n 's/.*soname: *\[\(.*\)\]/\1/p')"
|
||||
[ -n "$_son" ] && ln -sf "$(basename "$_real")" "$CTX/syslib/$_son"
|
||||
done
|
||||
cp_r /usr/lib/aarch64-linux-gnu/cmake/opencv4 "$CTX/syslib/cmake/"
|
||||
cp_r /usr/include/opencv4 "$CTX/sysinc/"
|
||||
cp_r /usr/include/nlohmann "$CTX/sysinc/"
|
||||
cp_r /usr/include/hobot "$CTX/sysinc/"
|
||||
elif [ -d /app/cdev_demo/bpu/src ]; then
|
||||
# X5: make 工程 (cd src && make); cdev 样例为相机驱动, 自测走 pydev 静态样例
|
||||
cp -a /app/cdev_demo/bpu/. "$CTX/src/"
|
||||
mkdir -p "$CTX/py_case/01_basic" "$CTX/py_case/models"
|
||||
cp_r /app/pydev_demo/01_basic_sample/test_mobilenetv1.py "$CTX/py_case/01_basic/"
|
||||
cp_r /opt/hobot/model/*/basic/mobilenetv1_224x224_nv12.bin "$CTX/py_case/models/"
|
||||
cp_r /app/pydev_demo/01_basic_sample/zebra_cls.jpg "$CTX/py_case/01_basic/" 2>/dev/null
|
||||
cp_r /app/res/assets/zebra_cls.jpg "$CTX/py_case/01_basic/"
|
||||
cp_r /app/res/labels/imagenet1000_clsidx_to_labels.txt "$CTX/py_case/01_basic/" 2>/dev/null
|
||||
cp_r /app/pydev_demo/01_basic_sample/imagenet1000_clsidx_to_labels.txt "$CTX/py_case/01_basic/" 2>/dev/null
|
||||
mkdir -p "$CTX/usrlib_root" "$CTX/syslib" "$CTX/sysinc" "$CTX/utils"
|
||||
cp_r /usr/lib/libpostprocess.so* "$CTX/usrlib_root/"
|
||||
cp_r /usr/lib/libspcdev.so* "$CTX/syslib/"
|
||||
cp_r /usr/lib/libhbspdev.so* "$CTX/syslib/"
|
||||
cp_r /usr/lib/libdnn.so* "$CTX/syslib/"
|
||||
cp_r /usr/lib/libhbrt_bayes*.so* "$CTX/syslib/"
|
||||
cp_r /usr/lib/libopencv_world.so* "$CTX/syslib/"
|
||||
cp_r /usr/lib/libsrcampy.so* "$CTX/syslib/" 2>/dev/null
|
||||
cp_r /usr/include/sp_*.h "$CTX/sysinc/"
|
||||
cp_r /usr/include/dnn "$CTX/sysinc/"
|
||||
cp_r /usr/include/opencv2 "$CTX/sysinc/"
|
||||
cp_r /usr/include/opencv4 "$CTX/sysinc/"
|
||||
cp_r /usr/include/android "$CTX/sysinc/"
|
||||
cp_r /usr/include/*.h "$CTX/sysinc/"
|
||||
else
|
||||
echo "[skip] 无 BPU 案例源码"; return 1
|
||||
fi
|
||||
local m
|
||||
m=$(ls /opt/hobot/model/*/basic/mobilenetv2_224x224_nv12.hbm 2>/dev/null | head -1)
|
||||
if [ -z "$m" ]; then
|
||||
m=$(ls /opt/hobot/model/*/basic/mobilenet*.hbm /opt/hobot/model/*/basic/mobilenet*.bin 2>/dev/null | head -1)
|
||||
fi
|
||||
if [ -z "$m" ]; then echo "[skip] 无 mobilenet 模型"; return 1; fi
|
||||
cp "$m" "$CTX/bpu_model.hbm"
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_bpu"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
|
||||
rt_base="$RUNTIME_BASE"
|
||||
# X5 的 bpu 自测走 python 样例, 运行层直接用 app_base (带 python3 与板卡包路径)
|
||||
[ "$FAMILY" = "bayese" ] && rt_base="$APP_BASE_TAG"
|
||||
|
||||
tag="case_bpu_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
28
examples/bpu/any/run.sh
Executable file
28
examples/bpu/any/run.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# bpu 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args bpu)" || { echo "[skip] bpu 单元定义错误"; exit 0; }
|
||||
|
||||
repo="case_bpu_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-bpu-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "bpu" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
57
examples/bpu/any/selftest.sh
Normal file
57
examples/bpu/any/selftest.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
# BPU 单元案例自测
|
||||
# S600/S100: mobilenetv2 分类 zebra 图, top1 应为 zebra
|
||||
# X5: bin/sample 检测样例, 正常加载模型并推理即通过
|
||||
cd /opt/test
|
||||
if [ -x ./build/mobilenetv2 ]; then
|
||||
BIN=./build/mobilenetv2
|
||||
elif [ -f ./py_case/01_basic/test_mobilenetv1.py ] && command -v python3 >/dev/null 2>&1; then
|
||||
# X5 特例: cdev bpu 样例为相机驱动, 用 pydev 静态分类样例自测
|
||||
# (脚本硬编码 ../models/ 与当前目录 zebra_cls.jpg)
|
||||
cd ./py_case/01_basic
|
||||
OUT=$(timeout 90 python3 test_mobilenetv1.py 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT" | grep -E "Classification|class_name|cls id" | head -5
|
||||
if [ $RC -eq 0 ] && echo "$OUT" | grep -qi "zebra"; then
|
||||
echo "TEST PASS (bpu: pydev mobilenetv1 top1=zebra)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (bpu pydev, rc=$RC)"
|
||||
exit 1
|
||||
elif [ -x ./bin/sample ]; then
|
||||
BIN=./bin/sample
|
||||
else
|
||||
# 产物在 HR_BUILD_OUTPUT_DIR (out/) 下
|
||||
BIN=$(find ./out -maxdepth 4 -type f -perm -u+x 2>/dev/null | grep -vE '\.(so|sh)$' | head -1)
|
||||
[ -z "$BIN" ] && BIN=$(find . -maxdepth 3 -type f -name sample -perm -u+x 2>/dev/null | head -1)
|
||||
fi
|
||||
if [ -z "$BIN" ] || [ ! -x "$BIN" ]; then
|
||||
echo "TEST FAIL (bpu: binary not found)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$BIN" = "./build/mobilenetv2" ]; then
|
||||
OUT=$(timeout 60 "$BIN" \
|
||||
--model_path /opt/test/model.hbm \
|
||||
--test_img /app/res/assets/zebra_cls.jpg \
|
||||
--label_file /app/res/labels/imagenet1000_clsidx_to_labels.txt \
|
||||
--top_k 5 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT" | tail -8
|
||||
if [ $RC -eq 0 ] && echo "$OUT" | grep -q "label=zebra"; then
|
||||
echo "TEST PASS (bpu: mobilenetv2 top1=zebra)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (bpu, rc=$RC)"
|
||||
exit 1
|
||||
else
|
||||
OUT=$(timeout 60 "$BIN" -m 0 -f /opt/test/model.hbm 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT" | tail -8
|
||||
if [ $RC -eq 0 ]; then
|
||||
echo "TEST PASS (bpu: sample loaded model and inferred)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (bpu, rc=$RC)"
|
||||
exit 1
|
||||
fi
|
||||
@ -8,7 +8,7 @@ HRT_BIN="$(which hrt_model_exec)"
|
||||
echo "Copying hrt_model_exec from $HRT_BIN"
|
||||
cp "$HRT_BIN" "$SCRIPT_DIR/hrt_model_exec"
|
||||
|
||||
docker build -f Dockerfile.nashem_perf -t hrt_perf_nashem:v3.7.3 "$SCRIPT_DIR"
|
||||
docker build -f Dockerfile -t "hrt_perf_bayese:$(date +%y%m%d_%H%M%S)" "$SCRIPT_DIR"
|
||||
|
||||
# Clean up copied binary
|
||||
rm -f "$SCRIPT_DIR/hrt_model_exec"
|
||||
@ -1,4 +1,12 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_bayese" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# Run the bayese perf container
|
||||
# Input: /workspace/input/task.json (mounted from host)
|
||||
# Output: /workspace/output/result.json (mounted from host)
|
||||
@ -11,6 +19,6 @@ docker run --rm \
|
||||
-v /opt/tros:/opt/tros:ro \
|
||||
-v /lib/aarch64-linux-gnu:/host_lib/aarch64-linux-gnu:ro \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-v $(pwd)/example_fs_bayese/input:/workspace/input:ro \
|
||||
-v $(pwd)/example_fs_bayese/output:/workspace/output \
|
||||
hrt_perf_bayese:v1.24.5
|
||||
-v $(pwd)/example_fs/input:/workspace/input:ro \
|
||||
-v $(pwd)/example_fs/output:/workspace/output \
|
||||
hrt_perf_bayese:${PERF_TAG}
|
||||
@ -1,4 +1,10 @@
|
||||
#!/bin/bash
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_bayese" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# 交互式启动 BaYeSe perf 容器,entrypoint 为 /bin/bash
|
||||
# 用于在容器内交互式使用 BPU(hrt_model_exec 等工具)
|
||||
|
||||
@ -12,4 +18,4 @@ docker run -it --rm \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-e ROS_DOMAIN_ID=0 \
|
||||
--entrypoint /bin/bash \
|
||||
hrt_perf_bayese:v1.24.5
|
||||
hrt_perf_bayese:${PERF_TAG}
|
||||
14
examples/bpu_model_perf/nashem/build.sh
Normal file
14
examples/bpu_model_perf/nashem/build.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# Copy hrt_model_exec into build context
|
||||
HRT_BIN="$(which hrt_model_exec)"
|
||||
echo "Copying hrt_model_exec from $HRT_BIN"
|
||||
cp "$HRT_BIN" "$SCRIPT_DIR/hrt_model_exec"
|
||||
|
||||
docker build -f Dockerfile -t "hrt_perf_nashem:$(date +%y%m%d_%H%M%S)" "$SCRIPT_DIR"
|
||||
|
||||
# Clean up copied binary
|
||||
rm -f "$SCRIPT_DIR/hrt_model_exec"
|
||||
@ -1,4 +1,12 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_nashem" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# Run the nashem perf container
|
||||
# Input: /workspace/input/task.json (mounted from host)
|
||||
# Output: /workspace/output/result.json (mounted from host)
|
||||
@ -13,4 +21,4 @@ docker run --rm \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-v $(pwd)/example_fs/input:/workspace/input:ro \
|
||||
-v $(pwd)/example_fs/output:/workspace/output \
|
||||
hrt_perf_nashem:v3.7.3
|
||||
hrt_perf_nashem:${PERF_TAG}
|
||||
@ -1,4 +1,10 @@
|
||||
#!/bin/bash
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_nashem" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# 交互式启动 NashEM perf 容器,entrypoint 为 /bin/bash
|
||||
# 用于在容器内交互式使用 BPU(hrt_model_exec 等工具)
|
||||
|
||||
@ -12,4 +18,4 @@ docker run -it --rm \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-e ROS_DOMAIN_ID=0 \
|
||||
--entrypoint /bin/bash \
|
||||
hrt_perf_nashem:v3.7.3
|
||||
hrt_perf_nashem:${PERF_TAG}
|
||||
20
examples/bpu_model_perf/nashem/workspace/entrypoint.sh
Normal file
20
examples/bpu_model_perf/nashem/workspace/entrypoint.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INPUT_DIR="/workspace/input"
|
||||
OUTPUT_DIR="/workspace/output"
|
||||
INPUT_JSON="${INPUT_DIR}/task.json"
|
||||
OUTPUT_JSON="${OUTPUT_DIR}/result.json"
|
||||
|
||||
# Allow overrides via env vars
|
||||
INPUT_JSON="${PERF_INPUT:-$INPUT_JSON}"
|
||||
OUTPUT_JSON="${PERF_OUTPUT:-$OUTPUT_JSON}"
|
||||
|
||||
if [ ! -f "$INPUT_JSON" ]; then
|
||||
echo "ERROR: input file not found: $INPUT_JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$OUTPUT_JSON")"
|
||||
|
||||
exec python3 /workspace/perf/perf.py --input "$INPUT_JSON" --output "$OUTPUT_JSON"
|
||||
221
examples/bpu_model_perf/nashem/workspace/perf.py
Normal file
221
examples/bpu_model_perf/nashem/workspace/perf.py
Normal file
@ -0,0 +1,221 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
BPU Model Performance Benchmark Tool
|
||||
Runs hrt_model_exec perf for each model at thread counts 1,2,3,4
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
HRT_MODEL_EXEC = "hrt_model_exec"
|
||||
THREAD_COUNTS = [1, 2, 3, 4]
|
||||
|
||||
|
||||
def run_perf(model_path: str, thread_num: int, frame_count: int = 200) -> dict:
|
||||
"""Run hrt_model_exec perf and return parsed results."""
|
||||
cmd = [
|
||||
HRT_MODEL_EXEC, "perf",
|
||||
"--model_file", model_path,
|
||||
"--thread_num", str(thread_num),
|
||||
"--frame_count", str(frame_count),
|
||||
]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
output = result.stdout + result.stderr
|
||||
|
||||
perf = {
|
||||
"thread_num": thread_num,
|
||||
"frame_count": frame_count,
|
||||
"run_time_ms": None,
|
||||
"total_latency_ms": None,
|
||||
"avg_latency_ms": None,
|
||||
"fps": None,
|
||||
"raw_output": output,
|
||||
"returncode": result.returncode,
|
||||
}
|
||||
|
||||
m = re.search(r"Program run time:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["run_time_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Frame totally latency is:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["total_latency_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Average\s+latency\s+is:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["avg_latency_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Frame\s+rate\s+is:\s*([\d.]+)\s*FPS", output)
|
||||
if m:
|
||||
perf["fps"] = float(m.group(1))
|
||||
|
||||
return perf
|
||||
|
||||
|
||||
def print_table(results: list):
|
||||
"""Print results as a human-readable table."""
|
||||
# 动态计算 model 列宽
|
||||
max_name_len = max(len(e["model_name"]) for e in results)
|
||||
col_widths = [max(max_name_len, 10), 9, 16, 10]
|
||||
headers = ["Model", "Threads", "Avg Latency(ms)", "FPS"]
|
||||
|
||||
sep = "+" + "+".join("-" * (w + 2) for w in col_widths) + "+"
|
||||
header_row = "|" + "|".join(
|
||||
f" {h:<{w}} " for h, w in zip(headers, col_widths)
|
||||
) + "|"
|
||||
|
||||
for entry in results:
|
||||
name = entry["model_name"]
|
||||
# 每个模型单独打印表头
|
||||
print(sep)
|
||||
print(header_row)
|
||||
print(sep)
|
||||
for p in entry["perf_results"]:
|
||||
avg = f"{p['avg_latency_ms']:.3f}" if p["avg_latency_ms"] is not None else "N/A"
|
||||
fps = f"{p['fps']:.2f}" if p["fps"] is not None else "N/A"
|
||||
row = [name, str(p["thread_num"]), avg, fps]
|
||||
print("|" + "|".join(
|
||||
f" {v:<{w}} " for v, w in zip(row, col_widths)
|
||||
) + "|")
|
||||
name = ""
|
||||
print(sep)
|
||||
|
||||
|
||||
def validate_config(config: dict, input_dir: Path) -> list:
|
||||
"""Print and validate task.json, return normalized model list. Exit on error."""
|
||||
print("=" * 60)
|
||||
print("task.json content:")
|
||||
print(json.dumps(config, indent=2, ensure_ascii=False))
|
||||
print("=" * 60)
|
||||
|
||||
errors = []
|
||||
|
||||
# --- frame_count ---
|
||||
if "frame_count" in config:
|
||||
if not isinstance(config["frame_count"], int) or config["frame_count"] <= 0:
|
||||
errors.append(" [frame_count] must be a positive integer")
|
||||
|
||||
# --- 判断格式 ---
|
||||
has_single = "model_relative_path" in config
|
||||
has_multi = "models" in config
|
||||
|
||||
if not has_single and not has_multi:
|
||||
errors.append(" missing required field: 'model_relative_path' or 'models'")
|
||||
for e in errors:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if has_single and has_multi:
|
||||
errors.append(" ambiguous: both 'model_relative_path' and 'models' are present, use one")
|
||||
|
||||
models = []
|
||||
|
||||
if has_single:
|
||||
rel = config["model_relative_path"]
|
||||
if not isinstance(rel, str) or not rel.strip():
|
||||
errors.append(" [model_relative_path] must be a non-empty string")
|
||||
elif not rel.endswith((".hbm", ".bin")):
|
||||
errors.append(f" [model_relative_path] unsupported extension: '{rel}' (expected .hbm or .bin)")
|
||||
else:
|
||||
models = [{"name": Path(rel).name, "path": rel}]
|
||||
|
||||
if has_multi:
|
||||
if not isinstance(config["models"], list) or len(config["models"]) == 0:
|
||||
errors.append(" [models] must be a non-empty list")
|
||||
else:
|
||||
for i, m in enumerate(config["models"]):
|
||||
prefix = f" [models[{i}]]"
|
||||
if not isinstance(m, dict):
|
||||
errors.append(f"{prefix} each entry must be an object")
|
||||
continue
|
||||
if "path" not in m:
|
||||
errors.append(f"{prefix} missing required field 'path'")
|
||||
elif not isinstance(m["path"], str) or not m["path"].strip():
|
||||
errors.append(f"{prefix} 'path' must be a non-empty string")
|
||||
elif not m["path"].endswith((".hbm", ".bin")):
|
||||
errors.append(f"{prefix} unsupported extension: '{m['path']}' (expected .hbm or .bin)")
|
||||
else:
|
||||
models.append({"name": m.get("name", Path(m["path"]).name), "path": m["path"]})
|
||||
|
||||
if errors:
|
||||
for e in errors:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# --- 文件存在性检查 ---
|
||||
missing = []
|
||||
for m in models:
|
||||
full = input_dir / m["path"]
|
||||
if not full.exists():
|
||||
missing.append(f" model file not found: {full}")
|
||||
if missing:
|
||||
for e in missing:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"[OK] {len(models)} model(s) validated, frame_count={config.get('frame_count', 200)}\n")
|
||||
return models
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="BPU model perf benchmark")
|
||||
parser.add_argument("--input", required=True, help="Input JSON file")
|
||||
parser.add_argument("--output", required=True, help="Output JSON file")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not Path(args.input).exists():
|
||||
print(f"[ERROR] input file not found: {args.input}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
with open(args.input) as f:
|
||||
config = json.load(f)
|
||||
|
||||
input_dir = Path(args.input).parent
|
||||
frame_count = config.get("frame_count", 200)
|
||||
models = validate_config(config, input_dir)
|
||||
|
||||
if not models:
|
||||
print("[ERROR] no models specified in input JSON", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
output_results = []
|
||||
|
||||
for model in models:
|
||||
rel_path = model["path"]
|
||||
model_path = str(input_dir / rel_path)
|
||||
model_name = model.get("name", Path(rel_path).name)
|
||||
print(f"\n[Benchmarking] {model_name} ({model_path})")
|
||||
|
||||
perf_results = []
|
||||
for t in THREAD_COUNTS:
|
||||
print(f" thread_num={t} ...", end=" ", flush=True)
|
||||
p = run_perf(model_path, t, frame_count)
|
||||
perf_results.append(p)
|
||||
if p["fps"] is not None:
|
||||
print(f"FPS={p['fps']:.2f} avg_latency={p['avg_latency_ms']:.3f}ms")
|
||||
else:
|
||||
print("FAILED (check raw_output in result JSON)")
|
||||
|
||||
output_results.append({
|
||||
"model_name": model_name,
|
||||
"model_path": model_path,
|
||||
"perf_results": perf_results,
|
||||
})
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print_table(output_results)
|
||||
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_path, "w") as f:
|
||||
json.dump(output_results, f, indent=2)
|
||||
|
||||
print(f"\nResults saved to: {args.output}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
68
examples/bpu_model_perf/nashp/Dockerfile
Normal file
68
examples/bpu_model_perf/nashp/Dockerfile
Normal file
@ -0,0 +1,68 @@
|
||||
# RDK S600 (Nash-p) 使用 ubuntu:24.04 基底:
|
||||
# S600 宿主机为 RDK OS V5.1.0 (Ubuntu 24.04, glibc 2.39),
|
||||
# 镜像内打包的 hrt_model_exec 链接 glibc 2.39, 22.04 基底 (glibc 2.35) 无法运行
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# ============================================================
|
||||
# 基础工具
|
||||
# SSH Server 安装和配置
|
||||
# ============================================================
|
||||
RUN apt-get update && apt-get install -y \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-venv \
|
||||
git \
|
||||
wget \
|
||||
curl \
|
||||
vim \
|
||||
sshpass \
|
||||
i2c-tools \
|
||||
software-properties-common \
|
||||
gnupg2 \
|
||||
lsb-release \
|
||||
openssh-server \
|
||||
locales \
|
||||
&& mkdir -p /var/run/sshd \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 配置中文 locale(防止终端中文乱码)
|
||||
RUN locale-gen zh_CN.UTF-8 && update-locale LANG=zh_CN.UTF-8
|
||||
ENV LANG=zh_CN.UTF-8
|
||||
ENV LC_ALL=zh_CN.UTF-8
|
||||
|
||||
# SSH 安全配置
|
||||
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
|
||||
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
|
||||
&& echo "MaxAuthTries 3" >> /etc/ssh/sshd_config \
|
||||
&& echo "MaxStartups 3:50:10" >> /etc/ssh/sshd_config \
|
||||
&& echo "LoginGraceTime 30" >> /etc/ssh/sshd_config \
|
||||
&& echo "ClientAliveInterval 60" >> /etc/ssh/sshd_config \
|
||||
&& echo "ClientAliveCountMax 3" >> /etc/ssh/sshd_config
|
||||
|
||||
# 生成 SSH Host Key(容器首次启动时会自动生成,这里预生成加速启动)
|
||||
RUN ssh-keygen -A
|
||||
|
||||
# 设置 root 密码
|
||||
RUN echo 'root:root' | chpasswd
|
||||
|
||||
# ============================================================
|
||||
# BPU Model Perf 工具
|
||||
# ============================================================
|
||||
|
||||
# 拷贝 hrt_model_exec(从宿主机板子上的路径)
|
||||
COPY hrt_model_exec /usr/local/bin/hrt_model_exec
|
||||
RUN chmod +x /usr/local/bin/hrt_model_exec
|
||||
|
||||
# 拷贝 perf 脚本和 entrypoint
|
||||
COPY workspace/perf.py /workspace/perf/perf.py
|
||||
COPY workspace/entrypoint.sh /workspace/perf/entrypoint.sh
|
||||
RUN chmod +x /workspace/perf/entrypoint.sh
|
||||
|
||||
# 工作目录和挂载点
|
||||
RUN mkdir -p /workspace/input /workspace/output
|
||||
|
||||
WORKDIR /workspace/perf
|
||||
|
||||
ENTRYPOINT ["/workspace/perf/entrypoint.sh"]
|
||||
@ -8,7 +8,7 @@ HRT_BIN="$(which hrt_model_exec)"
|
||||
echo "Copying hrt_model_exec from $HRT_BIN"
|
||||
cp "$HRT_BIN" "$SCRIPT_DIR/hrt_model_exec"
|
||||
|
||||
docker build -f Dockerfile.bayese_perf -t hrt_perf_bayese:v1.24.5 "$SCRIPT_DIR"
|
||||
docker build -f Dockerfile -t "hrt_perf_nashp:$(date +%y%m%d_%H%M%S)" "$SCRIPT_DIR"
|
||||
|
||||
# Clean up copied binary
|
||||
rm -f "$SCRIPT_DIR/hrt_model_exec"
|
||||
4
examples/bpu_model_perf/nashp/example_fs/input/task.json
Normal file
4
examples/bpu_model_perf/nashp/example_fs/input/task.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"model_relative_path": "yolo11n_detect_nashp_640x640_nv12.hbm",
|
||||
"frame_count": 20
|
||||
}
|
||||
48
examples/bpu_model_perf/nashp/example_fs/output/result.json
Normal file
48
examples/bpu_model_perf/nashp/example_fs/output/result.json
Normal file
@ -0,0 +1,48 @@
|
||||
[
|
||||
{
|
||||
"model_name": "yolo11n_detect_nashp_640x640_nv12.hbm",
|
||||
"model_path": "/workspace/input/yolo11n_detect_nashp_640x640_nv12.hbm",
|
||||
"perf_results": [
|
||||
{
|
||||
"thread_num": 1,
|
||||
"frame_count": 20,
|
||||
"run_time_ms": 19.471,
|
||||
"total_latency_ms": 18.592,
|
||||
"avg_latency_ms": 0.93,
|
||||
"fps": 1044.168,
|
||||
"raw_output": "[UCP]: log level = 3\n[UCP]: UCP version = 3.13.6\n[VP]: log level = 3\n[DNN]: log level = 3\n[HPL]: log level = 3\n[UCPT]: log level = 6\nhrt_model_exec perf --model_file /workspace/input/yolo11n_detect_nashp_640x640_nv12.hbm --thread_num 1 --frame_count 20\n\n\u001b[1;33m [Warning]: These operators have range limitations on input data: \u001b[0m\n\u001b[1;33m [Acos, Acosh, Asin, Atanh, BevPoolV2, Div, Gather, GatherElements, GatherND, GridSample, ImageDecoder, IndexSelect, Log, Mod, Pow, Reciprocal, RoiAlign, ScatterElements, ScatterND, Slice, Sqrt, Tan, Tile, Topk, Upsample]. \u001b[0m\n\u001b[1;33m Please make sure that these operators are not in your model, when no input data is provided to the tool. \u001b[0m\n\u001b[1;33m [Suggestion]: Using --input_file command to specify perf input data, which can appoint valid input data. \u001b[0m\n\n[BPU][[BPU_MONITOR]][281460798110176][INFO]BPULib verison(2, 2, 15)[f21ee84]!\n[DNN]: 3.13.6_(4.7.5 HBRT)\nLoad model to DDR cost 3895.53ms.\n\u001b[32m[I][9][10-20][04:01:27:381][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[0] stride is dynamic, but you did not specify the stride, set as (409600,640,1,1)\n\u001b[m\u001b[K\u001b[32m[I][9][10-20][04:01:27:383][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[1] stride is dynamic, but you did not specify the stride, set as (204800,640,2,1)\n\u001b[m\u001b[K\nRunning condition:\n Thread number is: 1\n Frame count is: 20\n Program run time: 19.471 ms\nPerf result:\n Frame totally latency is: 18.592 ms\n Average latency is: 0.930 ms\n Frame rate is: 1044.168 FPS\n",
|
||||
"returncode": 0
|
||||
},
|
||||
{
|
||||
"thread_num": 2,
|
||||
"frame_count": 20,
|
||||
"run_time_ms": 10.41,
|
||||
"total_latency_ms": 19.072,
|
||||
"avg_latency_ms": 0.96,
|
||||
"fps": 1968.708,
|
||||
"raw_output": "[UCP]: log level = 3\n[UCP]: UCP version = 3.13.6\n[VP]: log level = 3\n[DNN]: log level = 3\n[HPL]: log level = 3\n[UCPT]: log level = 6\nhrt_model_exec perf --model_file /workspace/input/yolo11n_detect_nashp_640x640_nv12.hbm --thread_num 2 --frame_count 20\n\n\u001b[1;33m [Warning]: These operators have range limitations on input data: \u001b[0m\n\u001b[1;33m [Acos, Acosh, Asin, Atanh, BevPoolV2, Div, Gather, GatherElements, GatherND, GridSample, ImageDecoder, IndexSelect, Log, Mod, Pow, Reciprocal, RoiAlign, ScatterElements, ScatterND, Slice, Sqrt, Tan, Tile, Topk, Upsample]. \u001b[0m\n\u001b[1;33m Please make sure that these operators are not in your model, when no input data is provided to the tool. \u001b[0m\n\u001b[1;33m [Suggestion]: Using --input_file command to specify perf input data, which can appoint valid input data. \u001b[0m\n\n[BPU][[BPU_MONITOR]][281457108892128][INFO]BPULib verison(2, 2, 15)[f21ee84]!\n[DNN]: 3.13.6_(4.7.5 HBRT)\nLoad model to DDR cost 3901.24ms.\n\u001b[32m[I][42][10-20][04:01:34:961][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[0] stride is dynamic, but you did not specify the stride, set as (409600,640,1,1)\n\u001b[m\u001b[K\u001b[32m[I][42][10-20][04:01:34:961][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[1] stride is dynamic, but you did not specify the stride, set as (204800,640,2,1)\n\u001b[m\u001b[K\nRunning condition:\n Thread number is: 2\n Frame count is: 20\n Program run time: 10.410 ms\nPerf result:\n Frame totally latency is: 19.072 ms\n Average latency is: 0.960 ms\n Frame rate is: 1968.708 FPS\n",
|
||||
"returncode": 0
|
||||
},
|
||||
{
|
||||
"thread_num": 3,
|
||||
"frame_count": 20,
|
||||
"run_time_ms": 7.677,
|
||||
"total_latency_ms": 20.355,
|
||||
"avg_latency_ms": 1.035,
|
||||
"fps": 2649.007,
|
||||
"raw_output": "[UCP]: log level = 3\n[UCP]: UCP version = 3.13.6\n[VP]: log level = 3\n[DNN]: log level = 3\n[HPL]: log level = 3\n[UCPT]: log level = 6\nhrt_model_exec perf --model_file /workspace/input/yolo11n_detect_nashp_640x640_nv12.hbm --thread_num 3 --frame_count 20\n\n\u001b[1;33m [Warning]: These operators have range limitations on input data: \u001b[0m\n\u001b[1;33m [Acos, Acosh, Asin, Atanh, BevPoolV2, Div, Gather, GatherElements, GatherND, GridSample, ImageDecoder, IndexSelect, Log, Mod, Pow, Reciprocal, RoiAlign, ScatterElements, ScatterND, Slice, Sqrt, Tan, Tile, Topk, Upsample]. \u001b[0m\n\u001b[1;33m Please make sure that these operators are not in your model, when no input data is provided to the tool. \u001b[0m\n\u001b[1;33m [Suggestion]: Using --input_file command to specify perf input data, which can appoint valid input data. \u001b[0m\n\n[BPU][[BPU_MONITOR]][281469152836064][INFO]BPULib verison(2, 2, 15)[f21ee84]!\n[DNN]: 3.13.6_(4.7.5 HBRT)\nLoad model to DDR cost 3874.97ms.\n\u001b[32m[I][76][10-20][04:01:42:449][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[0] stride is dynamic, but you did not specify the stride, set as (409600,640,1,1)\n\u001b[m\u001b[K\u001b[32m[I][76][10-20][04:01:42:449][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[1] stride is dynamic, but you did not specify the stride, set as (204800,640,2,1)\n\u001b[m\u001b[K\nRunning condition:\n Thread number is: 3\n Frame count is: 20\n Program run time: 7.677 ms\nPerf result:\n Frame totally latency is: 20.355 ms\n Average latency is: 1.035 ms\n Frame rate is: 2649.007 FPS\n",
|
||||
"returncode": 0
|
||||
},
|
||||
{
|
||||
"thread_num": 4,
|
||||
"frame_count": 20,
|
||||
"run_time_ms": 6.448,
|
||||
"total_latency_ms": 21.678,
|
||||
"avg_latency_ms": 1.124,
|
||||
"fps": 3063.615,
|
||||
"raw_output": "[UCP]: log level = 3\n[UCP]: UCP version = 3.13.6\n[VP]: log level = 3\n[DNN]: log level = 3\n[HPL]: log level = 3\n[UCPT]: log level = 6\nhrt_model_exec perf --model_file /workspace/input/yolo11n_detect_nashp_640x640_nv12.hbm --thread_num 4 --frame_count 20\n\n\u001b[1;33m [Warning]: These operators have range limitations on input data: \u001b[0m\n\u001b[1;33m [Acos, Acosh, Asin, Atanh, BevPoolV2, Div, Gather, GatherElements, GatherND, GridSample, ImageDecoder, IndexSelect, Log, Mod, Pow, Reciprocal, RoiAlign, ScatterElements, ScatterND, Slice, Sqrt, Tan, Tile, Topk, Upsample]. \u001b[0m\n\u001b[1;33m Please make sure that these operators are not in your model, when no input data is provided to the tool. \u001b[0m\n\u001b[1;33m [Suggestion]: Using --input_file command to specify perf input data, which can appoint valid input data. \u001b[0m\n\n[BPU][[BPU_MONITOR]][281463711513056][INFO]BPULib verison(2, 2, 15)[f21ee84]!\n[DNN]: 3.13.6_(4.7.5 HBRT)\nLoad model to DDR cost 3851.39ms.\n\u001b[32m[I][111][10-20][04:01:49:957][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[0] stride is dynamic, but you did not specify the stride, set as (409600,640,1,1)\n\u001b[m\u001b[K\u001b[32m[I][111][10-20][04:01:49:957][tensor_util.cpp:321][hrt_model_exec][HRT_MODEL_EXEC] Input[1] stride is dynamic, but you did not specify the stride, set as (204800,640,2,1)\n\u001b[m\u001b[K\nRunning condition:\n Thread number is: 4\n Frame count is: 20\n Program run time: 6.448 ms\nPerf result:\n Frame totally latency is: 21.678 ms\n Average latency is: 1.124 ms\n Frame rate is: 3063.615 FPS\n",
|
||||
"returncode": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
28
examples/bpu_model_perf/nashp/run.sh
Normal file
28
examples/bpu_model_perf/nashp/run.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_nashp" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# Run the nashp (RDK S600) perf container
|
||||
# Input: /workspace/input/task.json (mounted from host)
|
||||
# Output: /workspace/output/result.json (mounted from host)
|
||||
#
|
||||
# HB_DNN_USER_DEFINED_L2M_SIZES: 评测 L2 Cache 配置, 默认 6:6:6:6,
|
||||
# 宿主机已设置时使用宿主机的值
|
||||
|
||||
docker run --rm \
|
||||
--name hrt-perf-nashp \
|
||||
--privileged \
|
||||
-v /opt/hobot:/opt/hobot:ro \
|
||||
-v /usr/hobot:/usr/hobot:ro \
|
||||
-v /opt/tros:/opt/tros:ro \
|
||||
-v /lib/aarch64-linux-gnu:/host_lib/aarch64-linux-gnu:ro \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
-v $(pwd)/example_fs/input:/workspace/input:ro \
|
||||
-v $(pwd)/example_fs/output:/workspace/output \
|
||||
hrt_perf_nashp:${PERF_TAG}
|
||||
25
examples/bpu_model_perf/nashp/test.sh
Normal file
25
examples/bpu_model_perf/nashp/test.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
resolve_perf_tag() {
|
||||
docker images --format '{{.Tag}}' "hrt_perf_nashp" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
PERF_TAG="$(resolve_perf_tag)"
|
||||
[ -n "$PERF_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
# 交互式启动 Nash-p (RDK S600) perf 容器,entrypoint 为 /bin/bash
|
||||
# 用于在容器内交互式使用 BPU(hrt_model_exec 等工具)
|
||||
#
|
||||
# HB_DNN_USER_DEFINED_L2M_SIZES: 评测 L2 Cache 配置, 默认 6:6:6:6,
|
||||
# 宿主机已设置时使用宿主机的值
|
||||
|
||||
docker run -it --rm \
|
||||
--name hrt-perf-nashp-interactive \
|
||||
--privileged \
|
||||
-v /opt/hobot:/opt/hobot:ro \
|
||||
-v /usr/hobot:/usr/hobot:ro \
|
||||
-v /opt/tros:/opt/tros:ro \
|
||||
-v /lib/aarch64-linux-gnu:/host_lib/aarch64-linux-gnu:ro \
|
||||
-e LD_LIBRARY_PATH="/usr/hobot/lib:/host_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu" \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
-e ROS_DOMAIN_ID=0 \
|
||||
--entrypoint /bin/bash \
|
||||
hrt_perf_nashp:${PERF_TAG}
|
||||
20
examples/bpu_model_perf/nashp/workspace/entrypoint.sh
Normal file
20
examples/bpu_model_perf/nashp/workspace/entrypoint.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
INPUT_DIR="/workspace/input"
|
||||
OUTPUT_DIR="/workspace/output"
|
||||
INPUT_JSON="${INPUT_DIR}/task.json"
|
||||
OUTPUT_JSON="${OUTPUT_DIR}/result.json"
|
||||
|
||||
# Allow overrides via env vars
|
||||
INPUT_JSON="${PERF_INPUT:-$INPUT_JSON}"
|
||||
OUTPUT_JSON="${PERF_OUTPUT:-$OUTPUT_JSON}"
|
||||
|
||||
if [ ! -f "$INPUT_JSON" ]; then
|
||||
echo "ERROR: input file not found: $INPUT_JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$OUTPUT_JSON")"
|
||||
|
||||
exec python3 /workspace/perf/perf.py --input "$INPUT_JSON" --output "$OUTPUT_JSON"
|
||||
221
examples/bpu_model_perf/nashp/workspace/perf.py
Normal file
221
examples/bpu_model_perf/nashp/workspace/perf.py
Normal file
@ -0,0 +1,221 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
BPU Model Performance Benchmark Tool
|
||||
Runs hrt_model_exec perf for each model at thread counts 1,2,3,4
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
HRT_MODEL_EXEC = "hrt_model_exec"
|
||||
THREAD_COUNTS = [1, 2, 3, 4]
|
||||
|
||||
|
||||
def run_perf(model_path: str, thread_num: int, frame_count: int = 200) -> dict:
|
||||
"""Run hrt_model_exec perf and return parsed results."""
|
||||
cmd = [
|
||||
HRT_MODEL_EXEC, "perf",
|
||||
"--model_file", model_path,
|
||||
"--thread_num", str(thread_num),
|
||||
"--frame_count", str(frame_count),
|
||||
]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
output = result.stdout + result.stderr
|
||||
|
||||
perf = {
|
||||
"thread_num": thread_num,
|
||||
"frame_count": frame_count,
|
||||
"run_time_ms": None,
|
||||
"total_latency_ms": None,
|
||||
"avg_latency_ms": None,
|
||||
"fps": None,
|
||||
"raw_output": output,
|
||||
"returncode": result.returncode,
|
||||
}
|
||||
|
||||
m = re.search(r"Program run time:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["run_time_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Frame totally latency is:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["total_latency_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Average\s+latency\s+is:\s*([\d.]+)\s*ms", output)
|
||||
if m:
|
||||
perf["avg_latency_ms"] = float(m.group(1))
|
||||
|
||||
m = re.search(r"Frame\s+rate\s+is:\s*([\d.]+)\s*FPS", output)
|
||||
if m:
|
||||
perf["fps"] = float(m.group(1))
|
||||
|
||||
return perf
|
||||
|
||||
|
||||
def print_table(results: list):
|
||||
"""Print results as a human-readable table."""
|
||||
# 动态计算 model 列宽
|
||||
max_name_len = max(len(e["model_name"]) for e in results)
|
||||
col_widths = [max(max_name_len, 10), 9, 16, 10]
|
||||
headers = ["Model", "Threads", "Avg Latency(ms)", "FPS"]
|
||||
|
||||
sep = "+" + "+".join("-" * (w + 2) for w in col_widths) + "+"
|
||||
header_row = "|" + "|".join(
|
||||
f" {h:<{w}} " for h, w in zip(headers, col_widths)
|
||||
) + "|"
|
||||
|
||||
for entry in results:
|
||||
name = entry["model_name"]
|
||||
# 每个模型单独打印表头
|
||||
print(sep)
|
||||
print(header_row)
|
||||
print(sep)
|
||||
for p in entry["perf_results"]:
|
||||
avg = f"{p['avg_latency_ms']:.3f}" if p["avg_latency_ms"] is not None else "N/A"
|
||||
fps = f"{p['fps']:.2f}" if p["fps"] is not None else "N/A"
|
||||
row = [name, str(p["thread_num"]), avg, fps]
|
||||
print("|" + "|".join(
|
||||
f" {v:<{w}} " for v, w in zip(row, col_widths)
|
||||
) + "|")
|
||||
name = ""
|
||||
print(sep)
|
||||
|
||||
|
||||
def validate_config(config: dict, input_dir: Path) -> list:
|
||||
"""Print and validate task.json, return normalized model list. Exit on error."""
|
||||
print("=" * 60)
|
||||
print("task.json content:")
|
||||
print(json.dumps(config, indent=2, ensure_ascii=False))
|
||||
print("=" * 60)
|
||||
|
||||
errors = []
|
||||
|
||||
# --- frame_count ---
|
||||
if "frame_count" in config:
|
||||
if not isinstance(config["frame_count"], int) or config["frame_count"] <= 0:
|
||||
errors.append(" [frame_count] must be a positive integer")
|
||||
|
||||
# --- 判断格式 ---
|
||||
has_single = "model_relative_path" in config
|
||||
has_multi = "models" in config
|
||||
|
||||
if not has_single and not has_multi:
|
||||
errors.append(" missing required field: 'model_relative_path' or 'models'")
|
||||
for e in errors:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if has_single and has_multi:
|
||||
errors.append(" ambiguous: both 'model_relative_path' and 'models' are present, use one")
|
||||
|
||||
models = []
|
||||
|
||||
if has_single:
|
||||
rel = config["model_relative_path"]
|
||||
if not isinstance(rel, str) or not rel.strip():
|
||||
errors.append(" [model_relative_path] must be a non-empty string")
|
||||
elif not rel.endswith((".hbm", ".bin")):
|
||||
errors.append(f" [model_relative_path] unsupported extension: '{rel}' (expected .hbm or .bin)")
|
||||
else:
|
||||
models = [{"name": Path(rel).name, "path": rel}]
|
||||
|
||||
if has_multi:
|
||||
if not isinstance(config["models"], list) or len(config["models"]) == 0:
|
||||
errors.append(" [models] must be a non-empty list")
|
||||
else:
|
||||
for i, m in enumerate(config["models"]):
|
||||
prefix = f" [models[{i}]]"
|
||||
if not isinstance(m, dict):
|
||||
errors.append(f"{prefix} each entry must be an object")
|
||||
continue
|
||||
if "path" not in m:
|
||||
errors.append(f"{prefix} missing required field 'path'")
|
||||
elif not isinstance(m["path"], str) or not m["path"].strip():
|
||||
errors.append(f"{prefix} 'path' must be a non-empty string")
|
||||
elif not m["path"].endswith((".hbm", ".bin")):
|
||||
errors.append(f"{prefix} unsupported extension: '{m['path']}' (expected .hbm or .bin)")
|
||||
else:
|
||||
models.append({"name": m.get("name", Path(m["path"]).name), "path": m["path"]})
|
||||
|
||||
if errors:
|
||||
for e in errors:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# --- 文件存在性检查 ---
|
||||
missing = []
|
||||
for m in models:
|
||||
full = input_dir / m["path"]
|
||||
if not full.exists():
|
||||
missing.append(f" model file not found: {full}")
|
||||
if missing:
|
||||
for e in missing:
|
||||
print(f"[ERROR] {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"[OK] {len(models)} model(s) validated, frame_count={config.get('frame_count', 200)}\n")
|
||||
return models
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="BPU model perf benchmark")
|
||||
parser.add_argument("--input", required=True, help="Input JSON file")
|
||||
parser.add_argument("--output", required=True, help="Output JSON file")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not Path(args.input).exists():
|
||||
print(f"[ERROR] input file not found: {args.input}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
with open(args.input) as f:
|
||||
config = json.load(f)
|
||||
|
||||
input_dir = Path(args.input).parent
|
||||
frame_count = config.get("frame_count", 200)
|
||||
models = validate_config(config, input_dir)
|
||||
|
||||
if not models:
|
||||
print("[ERROR] no models specified in input JSON", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
output_results = []
|
||||
|
||||
for model in models:
|
||||
rel_path = model["path"]
|
||||
model_path = str(input_dir / rel_path)
|
||||
model_name = model.get("name", Path(rel_path).name)
|
||||
print(f"\n[Benchmarking] {model_name} ({model_path})")
|
||||
|
||||
perf_results = []
|
||||
for t in THREAD_COUNTS:
|
||||
print(f" thread_num={t} ...", end=" ", flush=True)
|
||||
p = run_perf(model_path, t, frame_count)
|
||||
perf_results.append(p)
|
||||
if p["fps"] is not None:
|
||||
print(f"FPS={p['fps']:.2f} avg_latency={p['avg_latency_ms']:.3f}ms")
|
||||
else:
|
||||
print("FAILED (check raw_output in result JSON)")
|
||||
|
||||
output_results.append({
|
||||
"model_name": model_name,
|
||||
"model_path": model_path,
|
||||
"perf_results": perf_results,
|
||||
})
|
||||
|
||||
print("\n" + "=" * 80)
|
||||
print_table(output_results)
|
||||
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_path, "w") as f:
|
||||
json.dump(output_results, f, indent=2)
|
||||
|
||||
print(f"\nResults saved to: {args.output}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
162
examples/common/app_base_common.sh
Normal file
162
examples/common/app_base_common.sh
Normal file
@ -0,0 +1,162 @@
|
||||
#!/bin/bash
|
||||
# app_base 运行脚本公共库 (被 docker_app_shell.sh / docker_app_bench.sh source)
|
||||
# 提供: 板型检测, 公共挂载参数构建, 按硬件单元的精确设备集构建
|
||||
|
||||
# ---------- 板型检测 ----------
|
||||
# /opt/hobot/model/ 下按板型命名: s600 -> nashp, s100 -> nashem, x5 -> bayese
|
||||
detect_family() {
|
||||
if [ -d /opt/hobot/model/s600 ]; then
|
||||
echo "nashp"
|
||||
elif [ -d /opt/hobot/model/s100 ]; then
|
||||
echo "nashem"
|
||||
elif [ -d /opt/hobot/model/x5 ]; then
|
||||
echo "bayese"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
FAMILY="$(detect_family)"
|
||||
if [ -z "$FAMILY" ]; then
|
||||
echo "[ERROR] 无法识别板型 (/opt/hobot/model/ 下无 s600/s100/x5)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# ---------- 公共挂载 (所有单元一致) ----------
|
||||
# 板卡库/工具/案例/模型/头文件/python包 全部来自宿主, 与固件版本一致
|
||||
build_common_mount_args() {
|
||||
local args=""
|
||||
for p in /usr/hobot /opt/hobot /app; do
|
||||
[ -d "$p" ] && args="$args -v $p:$p:ro"
|
||||
done
|
||||
# tros (若存在)
|
||||
[ -d /opt/tros ] && args="$args -v /opt/tros:/opt/tros:ro"
|
||||
# 宿主系统库与头文件 (usrmerge: /lib -> /usr/lib, 挂 /usr/lib 即全)
|
||||
[ -d /usr/lib ] && args="$args -v /usr/lib:/host_lib/usr_lib:ro"
|
||||
[ -d /usr/include ] && args="$args -v /usr/include:/host_inc/usr_include:ro"
|
||||
# 板卡相关配置
|
||||
for p in /etc/OpenCL /etc/libmm /etc/cam /etc/hobot.conf /etc/hobot_audio_config /etc/alternatives; do
|
||||
[ -e "$p" ] && args="$args -v $p:$p:ro"
|
||||
done
|
||||
# 板卡 python 包挂到同路径 (base 与板卡系统同代, python 小版本一致)
|
||||
local pydir
|
||||
for pydir in /usr/local/lib/python3.*/dist-packages; do
|
||||
[ -d "$pydir" ] && args="$args -v $pydir:$pydir:ro"
|
||||
done
|
||||
# 板卡命令直放路径 (X5 的 hrt_model_exec 等在 /usr/sbin, 不在 /usr/hobot/bin,
|
||||
# 以文件级挂载补到 /usr/local/bin 保证 PATH 可达)
|
||||
local f
|
||||
for f in /usr/sbin/hrt_model_exec /usr/sbin/hrt_bin_dump /usr/sbin/dnn_server; do
|
||||
if [ -f "$f" ]; then
|
||||
args="$args -v $f:/usr/local/bin/$(basename "$f"):ro"
|
||||
fi
|
||||
done
|
||||
echo "$args"
|
||||
}
|
||||
|
||||
# ---------- 按单元的精确设备集 ----------
|
||||
# 设备存在才挂载 (各板核心数/外设不同), 每个单元只给它需要的设备
|
||||
build_device_args() {
|
||||
local unit="$1"
|
||||
local args=""
|
||||
local d
|
||||
|
||||
add_if_exists() {
|
||||
[ -e "$1" ] && args="$args --device $1"
|
||||
}
|
||||
|
||||
case "$unit" in
|
||||
bpu)
|
||||
# BPU 推理: strace 实测仅需以下节点 (缺 /dev/ion 立即失败)
|
||||
add_if_exists /dev/bpu
|
||||
for i in 0 1 2 3 4 5 6 7; do add_if_exists /dev/bpu_core$i; done
|
||||
add_if_exists /dev/ion
|
||||
;;
|
||||
gpu)
|
||||
# GPU: nashp/nashem 为 Mali(mali0), bayese 为 GC820(galcore); dri 为渲染节点
|
||||
add_if_exists /dev/mali0
|
||||
add_if_exists /dev/galcore
|
||||
[ -d /dev/dri ] && args="$args --device /dev/dri"
|
||||
;;
|
||||
vpu)
|
||||
# 视频编解码: vpu/jpu 多核 + codec 通道 + 内存
|
||||
for d in /dev/vpu /dev/vpu1 /dev/vpu2 /dev/jpu /dev/jpu1 /dev/jpu2 \
|
||||
/dev/codec0_cap /dev/codec0_src; do
|
||||
add_if_exists "$d"
|
||||
done
|
||||
add_if_exists /dev/ion
|
||||
;;
|
||||
dsp)
|
||||
# DSP 单元 (统称): S600/S100 为 VDSP (vdspN+rpmsg_op+device_op,
|
||||
# 握手走 /dev/dcoreN_device_op); X5 为 aDSP (/dev/dsp + /dev/ipcdrv)
|
||||
for d in /dev/vdsp0 /dev/vdsp1 /dev/dcore0_rpmsg_op /dev/dcore1_rpmsg_op \
|
||||
/dev/dcore0_device_op /dev/dcore1_device_op \
|
||||
/dev/dsp /dev/ipcdrv; do
|
||||
add_if_exists "$d"
|
||||
done
|
||||
add_if_exists /dev/ion
|
||||
;;
|
||||
vio)
|
||||
# 相机/ISP/Pyramid/Stitch/GDC 通路 (sensor 探测走 i2c)
|
||||
for d in /dev/ion /dev/flow /dev/sensor_ctrl /dev/sensor_iq_calib \
|
||||
/dev/i2c-* /dev/vin* /dev/isp* /dev/pym* /dev/stitch* \
|
||||
/dev/gdc* /dev/ynr* /dev/idu* /dev/port_* /dev/deserial_* \
|
||||
/dev/mipi* /dev/video* /dev/media* /dev/vs-* /dev/n2d_*; do
|
||||
add_if_exists "$d"
|
||||
done
|
||||
;;
|
||||
mcu)
|
||||
# MCU 协处理器单元: 经 IPCF 跨核通信框架(/dev/ipcdrv)访问,
|
||||
# 含 40pin(GPIO/I2C/SPI/UART), CAN, timesync 等 MCU 侧服务
|
||||
for d in /dev/ipcdrv /dev/hrtc0 /dev/i2c-* /dev/spidev* /dev/ttyS* \
|
||||
/dev/gpiochip* /dev/pps* /dev/ptp* /dev/hbmem*; do
|
||||
add_if_exists "$d"
|
||||
done
|
||||
;;
|
||||
hbmem)
|
||||
# 共享内存 (S600 实测 hbmem 案例仅开 /dev/ion)
|
||||
add_if_exists /dev/ion
|
||||
for d in /dev/hbmem /dev/hbmem_pac*; do add_if_exists "$d"; done
|
||||
;;
|
||||
all)
|
||||
args="--privileged"
|
||||
;;
|
||||
*)
|
||||
echo "[ERROR] 未知单元: $unit (可选: bpu gpu vpu dsp vio mcu hbmem all)" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
echo "$args"
|
||||
}
|
||||
|
||||
# 单元中文名 (报告与提示用)
|
||||
unit_cn_name() {
|
||||
case "$1" in
|
||||
bpu) echo "BPU";;
|
||||
gpu) echo "GPU";;
|
||||
vpu) echo "VPU/JPU(CODEC)";;
|
||||
dsp) echo "DSP";;
|
||||
dsp) echo "DSP";;
|
||||
vio) echo "Camera/VIO";;
|
||||
mcu) echo "MCU协处理器(经IPCF)";;
|
||||
hbmem) echo "共享内存";;
|
||||
all) echo "全量(特权)";;
|
||||
esac
|
||||
}
|
||||
|
||||
# 镜像 tag 统一为 yymmdd_HHMMSS (由 build.sh 打包时生成),
|
||||
# 使用方经 resolve_tag 解析该仓库最新的时间 tag
|
||||
resolve_tag() {
|
||||
docker images --format '{{.Tag}}' "$1" 2>/dev/null \
|
||||
| grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1
|
||||
}
|
||||
|
||||
APP_BASE_TAG="app_base_${FAMILY}:$(resolve_tag app_base_${FAMILY})"
|
||||
# 注: 未构建时 APP_BASE_TAG 为空, 由使用方 (bench/shell/单元构建) 自行检查报错,
|
||||
# 这里不 exit —— common.sh 被 source, exit 会杀死调用方
|
||||
if [ -z "$(resolve_tag app_base_${FAMILY})" ]; then
|
||||
echo "[WARN] 未找到 app_base_${FAMILY} 时间 tag 镜像 (examples/app_base/any/build.sh 未运行)" >&2
|
||||
fi
|
||||
# 保证 source 返回 0, 不触发调用方的 set -e
|
||||
true
|
||||
30
examples/coremark/any/build.sh
Executable file
30
examples/coremark/any/build.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
# Build CoreMark-PRO benchmark Docker image
|
||||
# coremark-pro 源码 (65MB) 不入库, 首次构建时自动从镜像克隆
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
IMAGE_NAME="coremark_pro_rdk_arm"
|
||||
IMAGE_TAG="${1:-$(date +%y%m%d_%H%M%S)}"
|
||||
|
||||
# 自动获取 coremark-pro 源码 (优先 ghfast.top 镜像, 板上 github 不通)
|
||||
if [ ! -f "$SCRIPT_DIR/coremark-pro/benchmarks/Makefile" ]; then
|
||||
echo "[INFO] coremark-pro 源码不存在, 正在克隆..."
|
||||
rm -rf "$SCRIPT_DIR/coremark-pro"
|
||||
timeout 120 git clone --depth 1 \
|
||||
https://ghfast.top/https://github.com/eembc/coremark-pro.git \
|
||||
"$SCRIPT_DIR/coremark-pro" \
|
||||
&& rm -rf "$SCRIPT_DIR/coremark-pro/.git" \
|
||||
&& echo "[OK] coremark-pro 源码已克隆" \
|
||||
|| { echo "[ERROR] 克隆失败, 请手动获取 coremark-pro 源码"; exit 1; }
|
||||
fi
|
||||
|
||||
echo "Building CoreMark-PRO benchmark image..."
|
||||
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
echo ""
|
||||
|
||||
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f "$SCRIPT_DIR/Dockerfile" "$SCRIPT_DIR"
|
||||
|
||||
# 校验镜像真实存在 (构建失败时禁止假成功)
|
||||
docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} >/dev/null 2>&1 \
|
||||
&& echo "Build complete: ${IMAGE_NAME}:${IMAGE_TAG}" \
|
||||
|| { echo "Build FAILED"; exit 1; }
|
||||
1361
examples/coremark/any/example_fs/output/result.json
Normal file
1361
examples/coremark/any/example_fs/output/result.json
Normal file
File diff suppressed because it is too large
Load Diff
43
examples/coremark/any/run.sh
Executable file
43
examples/coremark/any/run.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# Run CoreMark-PRO CPU benchmark container
|
||||
# Output: /workspace/output/result.json (mounted from host)
|
||||
|
||||
IMAGE_NAME="coremark_pro_rdk_arm"
|
||||
IMAGE_TAG="$(docker images --format '{{.Tag}}' coremark_pro_rdk_arm 2>/dev/null | grep -E '^[0-9]{6}_[0-9]{6}$' | sort -r | head -1)"
|
||||
[ -n "$IMAGE_TAG" ] || { echo "[ERROR] 无时间 tag 镜像, 先运行 build.sh"; exit 1; }
|
||||
|
||||
# Default output directory on host
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
HOST_OUTPUT_DIR="${SCRIPT_DIR}/example_fs/output"
|
||||
|
||||
# Allow override via environment variable
|
||||
if [ -n "$COREMARK_OUTPUT_DIR" ]; then
|
||||
HOST_OUTPUT_DIR="$COREMARK_OUTPUT_DIR"
|
||||
fi
|
||||
|
||||
mkdir -p "$HOST_OUTPUT_DIR"
|
||||
|
||||
echo "Running CoreMark-PRO benchmark..."
|
||||
echo "Output will be saved to: $HOST_OUTPUT_DIR/result.json"
|
||||
echo ""
|
||||
|
||||
docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} >/dev/null 2>&1 \
|
||||
|| { echo "[ERROR] 镜像不存在, 先运行 build.sh"; exit 1; }
|
||||
|
||||
rm -f "$HOST_OUTPUT_DIR/result.json" # 清掉旧结果, 防止陈旧数据冒充本次输出
|
||||
|
||||
docker rm -f coremark_pro_rdk_arm >/dev/null 2>&1 || true # 清理残留同名容器
|
||||
docker run --rm \
|
||||
--name coremark_pro_rdk_arm \
|
||||
--privileged \
|
||||
-v "$HOST_OUTPUT_DIR":/workspace/output \
|
||||
${IMAGE_NAME}:${IMAGE_TAG}
|
||||
|
||||
if [ -f "$HOST_OUTPUT_DIR/result.json" ]; then
|
||||
echo ""
|
||||
echo "Benchmark complete. Results saved to: $HOST_OUTPUT_DIR/result.json"
|
||||
else
|
||||
echo ""
|
||||
echo "[ERROR] 未生成 result.json, 运行失败"
|
||||
exit 1
|
||||
fi
|
||||
@ -9,9 +9,17 @@ echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
echo ""
|
||||
|
||||
# Create test output directory
|
||||
mkdir -p "$(pwd)/example_fs/output"
|
||||
mkdir -p "${SCRIPT_DIR}/example_fs/output"
|
||||
[ -n "$SCRIPT_DIR" ] || SCRIPT_DIR="$(pwd)"
|
||||
|
||||
docker image inspect ${IMAGE_NAME}:${IMAGE_TAG} >/dev/null 2>&1 \
|
||||
|| { echo "[ERROR] 镜像不存在, 先运行 build.sh"; exit 1; }
|
||||
|
||||
# 清掉旧结果, 防止陈旧数据冒充本次输出
|
||||
rm -f "${SCRIPT_DIR}/example_fs/output/result.json"
|
||||
|
||||
# Run the benchmark
|
||||
docker rm -f coremark_pro_rdk_arm_test >/dev/null 2>&1 || true # 清理残留同名容器
|
||||
docker run --rm \
|
||||
--name coremark_pro_rdk_arm_test \
|
||||
--privileged \
|
||||
@ -21,11 +29,12 @@ docker run --rm \
|
||||
EXIT_CODE=$?
|
||||
|
||||
echo ""
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
if [ $EXIT_CODE -eq 0 ] && [ -f "${SCRIPT_DIR}/example_fs/output/result.json" ]; then
|
||||
echo "Test passed!"
|
||||
echo "Results available at: $(pwd)/example_fs/output/result.json"
|
||||
else
|
||||
echo "Test failed with exit code: $EXIT_CODE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit $EXIT_CODE
|
||||
exit 0
|
||||
27
examples/dsp/any/Dockerfile
Normal file
27
examples/dsp/any/Dockerfile
Normal file
@ -0,0 +1,27 @@
|
||||
# DSP 单元案例镜像 (统称 DSP): S600/S100 为 VDSP (vdsp_sample),
|
||||
# X5 为 aDSP (sample_dsp)。构建: build_case.sh dsp
|
||||
# 运行: run_case.sh dsp (透传 /dev/vdsp* /dev/dcore*_* /dev/dsp /dev/ipcdrv /dev/ion)
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY syslib /usr/lib/aarch64-linux-gnu
|
||||
COPY sysinc /usr/include
|
||||
COPY src /src
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
RUN mkdir -p /tmp/out && if [ -d /src/vdsp_sample ]; then \
|
||||
cd /src/vdsp_sample && make; \
|
||||
else \
|
||||
cd /src/sample_dsp && make; \
|
||||
fi
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /src /opt/test
|
||||
COPY --from=builder /tmp/out /opt/test/out
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
78
examples/dsp/any/build.sh
Executable file
78
examples/dsp/any/build.sh
Executable file
@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
# dsp 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_dsp_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
# DSP 单元 (统称): S600/S100 为 VDSP (vdsp_sample), X5 为 aDSP (sample_dsp)
|
||||
mkdir -p "$CTX/syslib" "$CTX/sysinc"
|
||||
if [ -d /app/vdsp_demo/vdsp_sample ]; then
|
||||
cp -a /app/vdsp_demo/vdsp_sample "$CTX/src"
|
||||
elif [ -d /app/multimedia_samples/sample_dsp ]; then
|
||||
cp -a /app/multimedia_samples/sample_dsp "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/Makefile.in "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/include "$CTX/src/"
|
||||
cp_r /usr/lib/aarch64-linux-gnu/libjsoncpp.so* "$CTX/syslib/"
|
||||
cp_r /usr/include/*.h "$CTX/sysinc/"
|
||||
cp_r /usr/include/android "$CTX/sysinc/"
|
||||
else
|
||||
echo "[skip] 无 DSP 案例"; return 1
|
||||
fi
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_dsp"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
rt_base="$RUNTIME_BASE"
|
||||
|
||||
tag="case_dsp_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
35
examples/dsp/any/run.sh
Executable file
35
examples/dsp/any/run.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# dsp 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args dsp)" || { echo "[skip] dsp 单元定义错误"; exit 0; }
|
||||
|
||||
# VDSP 固件 q8sample 由 hobot-multimedia-samples 包只放案例目录,
|
||||
# 内核 request_firmware 只搜 /lib/firmware, 缺失时装入 (厂商预期动作)
|
||||
if ls /dev/vdsp* >/dev/null 2>&1 && [ ! -f /lib/firmware/q8sample ]; then
|
||||
fw=$(ls /app/vdsp_demo/*/res/q8sample 2>/dev/null | head -1)
|
||||
[ -n "$fw" ] && cp "$fw" /lib/firmware/ && echo "[INFO] 已安装 DSP 固件到 /lib/firmware/q8sample"
|
||||
fi
|
||||
|
||||
repo="case_dsp_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-dsp-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "dsp" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
44
examples/dsp/any/selftest.sh
Normal file
44
examples/dsp/any/selftest.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# DSP 单元案例自测 (统称 DSP)
|
||||
# S600/S100: VDSP, vdsp_sample 加载 DSP 固件并执行
|
||||
# (固件 q8sample 由 run_case.sh 自动装入 /lib/firmware)
|
||||
# X5: aDSP, sample_dsp 需 /dev/dsp 与 /dev/ipcdrv;
|
||||
# 本内核无 DSP 核加载路径 (无 remoteproc/ipcf, 固件在
|
||||
# /usr/hobot/lib/firmware/adsp 但无法装载) 时判 SKIP。
|
||||
cd /opt/test
|
||||
|
||||
if [ -d /opt/test/vdsp_sample ] || [ -x ./vdsp_sample ]; then
|
||||
# ---- S600/S100: VDSP ----
|
||||
cd /opt/test/vdsp_sample
|
||||
OUT=$(timeout 60 ./vdsp_sample -d 0 -p res/q8sample -t 0 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT"
|
||||
if [ $RC -eq 0 ] && ! echo "$OUT" | grep -qE "vdsp start fail|Failed to read"; then
|
||||
echo "TEST PASS (dsp: vdsp_sample executed)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (dsp/vdsp, rc=$RC)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---- X5: aDSP ----
|
||||
if [ ! -e /dev/ipcdrv ] || [ ! -e /dev/dsp ]; then
|
||||
echo "TEST SKIP (dsp: 本内核无 DSP 核加载路径 - /dev/dsp 与 /dev/ipcdrv 不存在,"
|
||||
echo " 固件在 /usr/hobot/lib/firmware/adsp 但无 remoteproc/ipcf 装载机制)"
|
||||
exit 0
|
||||
fi
|
||||
BIN=./sample_dsp
|
||||
[ -x "$BIN" ] || BIN=$(find ./out -maxdepth 4 -type f -name sample_dsp -perm -u+x 2>/dev/null | head -1)
|
||||
if [ -z "$BIN" ] || [ ! -x "$BIN" ]; then
|
||||
echo "TEST FAIL (dsp/adsp: binary not found)"
|
||||
exit 1
|
||||
fi
|
||||
OUT=$(timeout 60 "$BIN" 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT" | tail -8
|
||||
if [ $RC -eq 0 ]; then
|
||||
echo "TEST PASS (dsp: adsp sample executed)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (dsp/adsp, rc=$RC)"
|
||||
exit 1
|
||||
22
examples/gpu/any/Dockerfile
Normal file
22
examples/gpu/any/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# GPU 单元案例镜像: OpenCL 矩阵乘 (sample_gpu_3d/cl, 单一硬件: GPU)
|
||||
# 构建: build_case.sh gpu
|
||||
# 运行: run_case.sh gpu (透传 /dev/mali0 或 /dev/galcore + /dev/dri)
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY syslib /usr/lib/aarch64-linux-gnu
|
||||
COPY sysinc /usr/include
|
||||
COPY src /src
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
RUN mkdir -p /tmp/out && cd /src/sample_gpu_3d/cl/sample_matrix_multiply && make
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /src/sample_gpu_3d/cl/sample_matrix_multiply/matrix_multiply /opt/test/
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
72
examples/gpu/any/build.sh
Executable file
72
examples/gpu/any/build.sh
Executable file
@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
# gpu 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_gpu_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
mkdir -p "$CTX/src/sample_gpu_3d/cl" "$CTX/sysinc" "$CTX/syslib"
|
||||
cp -a /app/multimedia_samples/sample_gpu_3d/cl/sample_matrix_multiply \
|
||||
"$CTX/src/sample_gpu_3d/cl/"
|
||||
# X5 的 Makefile include ../../../Makefile.in, S600 不需要但放入无害
|
||||
cp_r /app/multimedia_samples/Makefile.in "$CTX/src/"
|
||||
# X5 的 cl 样例链接 -ldrm; 板上系统头文件在 /usr/include 顶层
|
||||
cp_r /usr/lib/aarch64-linux-gnu/libdrm.so* "$CTX/syslib/"
|
||||
cp_r /usr/include/*.h "$CTX/sysinc/"
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_gpu"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
rt_base="$RUNTIME_BASE"
|
||||
|
||||
tag="case_gpu_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
28
examples/gpu/any/run.sh
Executable file
28
examples/gpu/any/run.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# gpu 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args gpu)" || { echo "[skip] gpu 单元定义错误"; exit 0; }
|
||||
|
||||
repo="case_gpu_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-gpu-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "gpu" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
12
examples/gpu/any/selftest.sh
Normal file
12
examples/gpu/any/selftest.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# GPU 单元案例自测: OpenCL 矩阵乘, GPU 结果应与 CPU 参照一致
|
||||
cd /opt/test
|
||||
OUT=$(timeout 60 ./matrix_multiply 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT"
|
||||
if [ $RC -eq 0 ] && echo "$OUT" | grep -q "Matrices are identical"; then
|
||||
echo "TEST PASS (gpu: opencl matrix_multiply result identical)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (gpu, rc=$RC)"
|
||||
exit 1
|
||||
22
examples/hbmem/any/Dockerfile
Normal file
22
examples/hbmem/any/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# 共享内存单元案例镜像 (单一硬件: ION/hbmem 内存)
|
||||
# S600/S100: communication_demo/hbmem_demo/sample_hbmem (输出 libhbmem_sample)
|
||||
# X5: multimedia_samples/sample_hbmem (输出 sample_hbmem, 需 -m 2)
|
||||
# 构建: build_case.sh hbmem ; 运行: run_case.sh hbmem
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY sysinc /usr/include
|
||||
COPY src /src
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
RUN mkdir -p /tmp/out && cd /src/sample_hbmem && make || cd /src && make
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /src /opt/test
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
75
examples/hbmem/any/build.sh
Executable file
75
examples/hbmem/any/build.sh
Executable file
@ -0,0 +1,75 @@
|
||||
#!/bin/bash
|
||||
# hbmem 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_hbmem_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
mkdir -p "$CTX/src" "$CTX/sysinc"
|
||||
cp_r /usr/include/*.h "$CTX/sysinc/"
|
||||
if [ -d /app/communication_demo/hbmem_demo/sample_hbmem ]; then
|
||||
cp -a /app/communication_demo/hbmem_demo/sample_hbmem "$CTX/src/"
|
||||
elif [ -d /app/multimedia_samples/sample_hbmem ]; then
|
||||
cp -a /app/multimedia_samples/sample_hbmem "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/Makefile.in "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/include "$CTX/src/"
|
||||
else
|
||||
echo "[skip] 无案例"; return 1
|
||||
fi
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_hbmem"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
rt_base="$RUNTIME_BASE"
|
||||
|
||||
tag="case_hbmem_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
28
examples/hbmem/any/run.sh
Executable file
28
examples/hbmem/any/run.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# hbmem 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args hbmem)" || { echo "[skip] hbmem 单元定义错误"; exit 0; }
|
||||
|
||||
repo="case_hbmem_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-hbmem-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "hbmem" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
22
examples/hbmem/any/selftest.sh
Normal file
22
examples/hbmem/any/selftest.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# 共享内存单元案例自测: cached/uncached memset 用例完成
|
||||
# 二进制名因板而异: S600/S100 为 libhbmem_sample, X5 为 sample_hbmem (需 -m 2)
|
||||
cd /opt/test/sample_hbmem 2>/dev/null || cd /opt/test
|
||||
BIN=""
|
||||
[ -x ./libhbmem_sample ] && BIN=./libhbmem_sample
|
||||
[ -x ./sample_hbmem ] && BIN=./sample_hbmem
|
||||
ARGS=""
|
||||
[ "$BIN" = "./sample_hbmem" ] && ARGS="-m 2"
|
||||
if [ -z "$BIN" ]; then
|
||||
echo "TEST FAIL (hbmem: binary not found)"
|
||||
exit 1
|
||||
fi
|
||||
OUT=$(timeout 60 "$BIN" $ARGS 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT" | grep -E "memset|done" | head -8
|
||||
if [ $RC -eq 0 ] && echo "$OUT" | grep -q "memset uncached buf"; then
|
||||
echo "TEST PASS (hbmem: $BIN memset done)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (hbmem, rc=$RC)"
|
||||
exit 1
|
||||
20
examples/mcu/any/Dockerfile
Normal file
20
examples/mcu/any/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
# MCU 单元案例镜像: ipcbox_runcmd (硬件对端: MCU 协处理器, 经 IPCF 跨核通信访问)
|
||||
# 构建: build_case.sh mcu
|
||||
# 运行: run_case.sh mcu (透传 /dev/ipcdrv)
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY src /src
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
RUN mkdir -p /tmp/out && cd /src/ipcbox_sample/ipcbox_runcmd && make
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /src /opt/test
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
70
examples/mcu/any/build.sh
Executable file
70
examples/mcu/any/build.sh
Executable file
@ -0,0 +1,70 @@
|
||||
#!/bin/bash
|
||||
# mcu 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_mcu_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
# MCU 单元: ipcbox_runcmd 经 IPCF 与 MCU 协处理器收发 (S600/S100)
|
||||
if [ -d /app/ipcbox_sample/ipcbox_runcmd ]; then
|
||||
cp -a /app/ipcbox_sample "$CTX/src"
|
||||
else
|
||||
echo "[skip] 无 ipcbox 案例"; return 1
|
||||
fi
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_mcu"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
rt_base="$RUNTIME_BASE"
|
||||
|
||||
tag="case_mcu_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
21
examples/mcu/any/firmware/README.md
Normal file
21
examples/mcu/any/firmware/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# MCU 固件版本记录
|
||||
|
||||
| 文件 | 板 | BSP 版本 | 编译产物 | MD5 | 大小 |
|
||||
|---|---|---|---|---|---|
|
||||
| s600_mcu1_fw.elf | RDK S600 | RDKS600_V5.1.0 | S600_MCU_RELEASE.elf (strip-debug) | 0132a9377a3bdaa35ca46212922085dc | 1.6 MB |
|
||||
| s100_mcu1_fw.elf | RDK S100 | RDKS100_V4.0.5-20260507 | S100_MCU_RELEASE.elf (strip-debug) | dfba9ecd6061dc21a07e55ee17f86301 | 1.6 MB |
|
||||
|
||||
## 来源
|
||||
|
||||
固件从对应版本 BSP 包的 RDKS*_MCU_SDK/board_support_package/firmwares/mcu1-product.zip
|
||||
中提取 RELEASE.elf 并执行 `objcopy --strip-debug` 剥离调试信息 (34MB 缩减到 1.6MB)。
|
||||
|
||||
BSP 版本更新后需重新提取并更新此目录, 同时更新上表中的版本号与 MD5。
|
||||
|
||||
## BSP 版本查看方法
|
||||
|
||||
板上执行:
|
||||
```
|
||||
cat /etc/os-release | grep VERSION
|
||||
```
|
||||
或查看 /root/ssd/chao01.wu/BSP/ 下的 SDK 目录名。
|
||||
BIN
examples/mcu/any/firmware/s100_mcu1_fw.elf
Executable file
BIN
examples/mcu/any/firmware/s100_mcu1_fw.elf
Executable file
Binary file not shown.
BIN
examples/mcu/any/firmware/s600_mcu1_fw.elf
Executable file
BIN
examples/mcu/any/firmware/s600_mcu1_fw.elf
Executable file
Binary file not shown.
92
examples/mcu/any/install_mcu_runtime.sh
Normal file
92
examples/mcu/any/install_mcu_runtime.sh
Normal file
@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
# S600/S100 MCU 运行时装载: 把仓库中的 MCU 产品固件装入 /lib/firmware,
|
||||
# 并创建 systemd 开机自启单元, 使 remoteproc_mcu1 在每次上电后自动启动。
|
||||
# MCU 起来后 ipcbox/can/timesync 等 cpu2mcu 案例即可用。
|
||||
#
|
||||
# 固件来源与版本: 见本目录 firmware/README.md
|
||||
# 如需从 BSP 源码重新编译, 方法如下 (在 x86_64 Linux 主机上):
|
||||
# 1. 解压 BSP 中 cross_compile_toolchain/gcc-arm-none-eabi-*.tar.bz2 并加入 PATH
|
||||
# 2. 解压 board_support_package/mcu-platform_source_code.tar.gz
|
||||
# 3. 按 SDK 内构建说明编译, 产物中取 *RELEASE.elf
|
||||
# 4. objcopy --strip-debug 剥离调试信息后替换 firmware/ 目录内文件
|
||||
# 并更新 firmware/README.md 中的版本号与 MD5
|
||||
#
|
||||
# 固件来源优先级:
|
||||
# 1. 仓库 firmware/<board>_mcu1_fw.elf (已剥离, 版本见 firmware/README.md)
|
||||
# 2. 板上 BSP SDK 的 mcu1-product.zip (解包取 RELEASE.elf 并剥离)
|
||||
#
|
||||
# 用法: bash install_mcu_runtime.sh [--from-bsp <BSP路径>]
|
||||
set -e
|
||||
|
||||
FW_DST="/lib/firmware/rproc-soc:remoteproc_mcu1-fw"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# 板型识别
|
||||
if [ -d /opt/hobot/model/s600 ]; then
|
||||
BOARD=s600
|
||||
elif [ -d /opt/hobot/model/s100 ]; then
|
||||
BOARD=s100
|
||||
else
|
||||
echo "[ERROR] 无法识别板型 (仅支持 s600/s100)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install_fw() {
|
||||
# 来源 1: 仓库内固件 (版本见 firmware/README.md)
|
||||
if [ -f "$SCRIPT_DIR/firmware/${BOARD}_mcu1_fw.elf" ]; then
|
||||
cp "$SCRIPT_DIR/firmware/${BOARD}_mcu1_fw.elf" "$FW_DST"
|
||||
echo "[OK] 已从仓库装入 ${BOARD} 固件 (版本见 firmware/README.md)"
|
||||
return 0
|
||||
fi
|
||||
# 来源 2: 板上 BSP SDK
|
||||
local zip
|
||||
zip=$(ls /root/ssd/*/bsp/RDKS*_LNX_SDK/*/RDKS*_MCU_SDK/board_support_package/firmwares/mcu1-product.zip \
|
||||
/root/ssd/*/BSP/RDKS*_LNX_SDK/*/RDKS*_MCU_SDK/board_support_package/firmwares/mcu1-product.zip 2>/dev/null | head -1)
|
||||
if [ -n "$zip" ]; then
|
||||
local tmp elf
|
||||
tmp=$(mktemp -d)
|
||||
unzip -o -q "$zip" -d "$tmp"
|
||||
elf=$(find "$tmp" -name '*RELEASE.elf' | head -1)
|
||||
cp "$elf" "$tmp/fw.elf"
|
||||
objcopy --strip-debug "$tmp/fw.elf" 2>/dev/null || true
|
||||
mv "$tmp/fw.elf" "$FW_DST"
|
||||
rm -rf "$tmp"
|
||||
echo "[OK] 已从 BSP 解包并剥离调试信息后装入 ${BOARD} 固件"
|
||||
return 0
|
||||
fi
|
||||
echo "[ERROR] 无固件来源 (仓库 firmware/ 目录或 BSP mcu1-product.zip)" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ ! -f "$FW_DST" ]; then
|
||||
install_fw
|
||||
else
|
||||
echo "[INFO] 固件已存在: $FW_DST"
|
||||
fi
|
||||
|
||||
# 立即启动 (若未运行)
|
||||
if ! grep -q running /sys/class/remoteproc/remoteproc_mcu1/state 2>/dev/null; then
|
||||
echo start > /sys/class/remoteproc/remoteproc_mcu1/state
|
||||
sleep 2
|
||||
fi
|
||||
echo "[INFO] mcu1 状态: $(cat /sys/class/remoteproc/remoteproc_mcu1/state)"
|
||||
|
||||
# systemd 开机自启
|
||||
cat > /etc/systemd/system/hobot-mcu1-boot.service <<'EOF'
|
||||
[Unit]
|
||||
Description=Boot MCU1 firmware (rproc-soc:remoteproc_mcu1-fw)
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/bin/sh -c 'grep -q running /sys/class/remoteproc/remoteproc_mcu1/state || echo start > /sys/class/remoteproc/remoteproc_mcu1/state'
|
||||
ExecStop=/bin/sh -c 'echo stop > /sys/class/remoteproc/remoteproc_mcu1/state'
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
systemctl enable hobot-mcu1-boot.service >/dev/null 2>&1
|
||||
echo "[OK] 已创建并启用 hobot-mcu1-boot.service (开机自动拉起 MCU1)"
|
||||
echo "[OK] 完成。可用本目录 run.sh 验证 (回显 ADC 数据)"
|
||||
37
examples/mcu/any/run.sh
Executable file
37
examples/mcu/any/run.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
# mcu 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args mcu)" || { echo "[skip] mcu 单元定义错误"; exit 0; }
|
||||
|
||||
# MCU 未运行时自动从仓库固件拉起 (版本见 firmware/README.md)
|
||||
mcu_running=0
|
||||
for r in /sys/class/remoteproc/remoteproc_mcu*; do
|
||||
[ -f "$r/state" ] && grep -q running "$r/state" && mcu_running=1
|
||||
done
|
||||
if [ "$mcu_running" != "1" ] && [ -f "$SCRIPT_DIR/install_mcu_runtime.sh" ]; then
|
||||
bash "$SCRIPT_DIR/install_mcu_runtime.sh" || true
|
||||
fi
|
||||
|
||||
repo="case_mcu_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-mcu-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "mcu" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
28
examples/mcu/any/selftest.sh
Normal file
28
examples/mcu/any/selftest.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# MCU 单元案例自测: ipcbox_runcmd 经 IPCF 向 MCU 发送命令并等待回显
|
||||
# (IPCF 是跨核通信底座, 硬件对端是 MCU 协处理器)
|
||||
# 前置条件: 板上 MCU 必须已运行 (闪存需有 MCU 分区且固件已烧写)。
|
||||
# 实测 S600/S100 出厂闪存无 MCU 分区, remoteproc_mcu0/1 永远 offline,
|
||||
# 该情况下无法收发 (宿主机同样无法收发), 判定为 SKIP 而非 FAIL。
|
||||
cd /opt/test/ipcbox_sample/ipcbox_runcmd
|
||||
|
||||
# MCU 存在性探测: 任一 mcu remoteproc 处于 running 才继续
|
||||
mcu_running=0
|
||||
for r in /sys/class/remoteproc/remoteproc_mcu*; do
|
||||
[ -f "$r/state" ] && grep -q running "$r/state" && mcu_running=1
|
||||
done
|
||||
if [ "$mcu_running" != "1" ]; then
|
||||
echo "TEST SKIP (mcu: 板上 MCU 未运行 - 闪存无 MCU 分区/固件, 宿主机同样无法收发)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
OUT=$(timeout 30 ./ipcbox_runcmd 2>&1)
|
||||
RC=$?
|
||||
echo "$OUT"
|
||||
# 通过判据: 拿到 MCU 回显数据 (样例完成数据交换后退出码非 0, 属其自身行为)
|
||||
if echo "$OUT" | grep -q "Extracted adc data" && ! echo "$OUT" | grep -q "send failed"; then
|
||||
echo "TEST PASS (mcu: ipcbox_runcmd exchanged with MCU)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (mcu, rc=$RC)"
|
||||
exit 1
|
||||
22
examples/vpu/any/Dockerfile
Normal file
22
examples/vpu/any/Dockerfile
Normal file
@ -0,0 +1,22 @@
|
||||
# VPU 单元案例镜像: H264 编解码样例 (sample_codec, 单一硬件: VPU)
|
||||
# 构建: build_case.sh vpu
|
||||
# 运行: run_case.sh vpu (透传 /dev/vpu* /dev/jpu* /dev/codec0_* /dev/ion)
|
||||
ARG BASE=app_base_nashp:v1.0.0
|
||||
ARG RUNTIME=ubuntu:24.04
|
||||
|
||||
FROM ${BASE} AS builder
|
||||
COPY usr/hobot/lib /usr/hobot/lib
|
||||
COPY usr/hobot/include /usr/hobot/include
|
||||
COPY syslib /usr/lib/aarch64-linux-gnu
|
||||
COPY sysinc /usr/include
|
||||
COPY src /src
|
||||
ENV HR_BUILD_OUTPUT_DIR=/tmp/out
|
||||
ENV CROSS_COMPILE=/usr/bin/
|
||||
RUN mkdir -p /tmp/out && cd /src/sample_codec && make
|
||||
|
||||
FROM ${RUNTIME}
|
||||
ENV LD_LIBRARY_PATH=/usr/hobot/lib:/host_lib/usr_lib:/host_lib/usr_lib/aarch64-linux-gnu:/lib/aarch64-linux-gnu:/usr/lib/aarch64-linux-gnu
|
||||
COPY --from=builder /src/sample_codec /opt/test
|
||||
COPY selftest.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh && cd /opt/test && rm -f *.o
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
84
examples/vpu/any/build.sh
Executable file
84
examples/vpu/any/build.sh
Executable file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
# vpu 单元案例镜像构建: 从板上 /app 取案例源码 + 链接库子集组装上下文,
|
||||
# 多阶段编译产出 case_vpu_<family>:<yymmdd_HHMMSS> (案例与自测入口均在镜像内)
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
[ -n "$APP_BASE_TAG" ] || { echo "[ERROR] 未找到 app_base 时间 tag 镜像, 先运行 examples/app_base/any/build.sh"; exit 1; }
|
||||
|
||||
case "$FAMILY" in
|
||||
nashp) RUNTIME_BASE="ubuntu:24.04" ;;
|
||||
*) RUNTIME_BASE="ubuntu:22.04" ;;
|
||||
esac
|
||||
|
||||
cp_r() { cp -a "$@" 2>/dev/null || true; }
|
||||
|
||||
# 展开 syslib 中 .so 的传递依赖 (来自 /usr/lib/aarch64-linux-gnu 的部分),
|
||||
# 否则链接期报 undefined reference (opencv/ffmpeg 依赖 tbb/openjp2 等)
|
||||
expand_syslib_deps() {
|
||||
[ -d "$CTX/syslib" ] || return 0
|
||||
[ -n "$(ls "$CTX/syslib"/*.so* 2>/dev/null)" ] || return 0
|
||||
local added=1 round=0
|
||||
while [ $added -eq 1 ] && [ $round -lt 6 ]; do
|
||||
added=0; round=$((round+1))
|
||||
local so dep base
|
||||
for so in "$CTX/syslib/"*.so*; do
|
||||
[ -f "$so" ] || continue
|
||||
for dep in $(LD_LIBRARY_PATH="$CTX/syslib:/usr/hobot/lib" ldd "$so" 2>/dev/null | awk '/=> \//{print $3}'); do
|
||||
# usrmerge: /lib -> /usr/lib, ldd 可能给出任一路径, 统一按 /usr/lib 处理
|
||||
case "$dep" in
|
||||
/lib/aarch64-linux-gnu/*|/usr/lib/aarch64-linux-gnu/*)
|
||||
base="$(basename "$dep")"
|
||||
if ! ls "$CTX/syslib/$base" >/dev/null 2>&1; then
|
||||
cp_r /usr/lib/aarch64-linux-gnu/"$base"* "$CTX/syslib/"
|
||||
# 符号链接的真实目标文件也要拷 (否则断链)
|
||||
local real
|
||||
real="$(readlink -f "$dep" 2>/dev/null)"
|
||||
[ -n "$real" ] && cp_r "$(dirname "$real")/$(basename "$real")"* "$CTX/syslib/"
|
||||
added=1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
assemble() {
|
||||
# sample_codec 同时验证 VPU(H264/H265) 与 JPU(JPEG), 双路径自测
|
||||
mkdir -p "$CTX/src"
|
||||
cp -a /app/multimedia_samples/sample_codec "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/Makefile.in "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/include "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/utils "$CTX/src/"
|
||||
cp_r /app/multimedia_samples/vp_sensors "$CTX/src/"
|
||||
# ffmpeg/ssl/drm 链接库 + 头文件
|
||||
mkdir -p "$CTX/syslib" "$CTX/sysinc"
|
||||
local l
|
||||
for l in libavformat libavcodec libavutil libswresample libcjson libssl libcrypto libz libdrm; do
|
||||
cp_r /usr/lib/aarch64-linux-gnu/${l}.so* "$CTX/syslib/"
|
||||
done
|
||||
local h
|
||||
for h in /usr/include/aarch64-linux-gnu/libavcodec /usr/include/aarch64-linux-gnu/libavformat \
|
||||
/usr/include/aarch64-linux-gnu/libavutil /usr/include/aarch64-linux-gnu/libswresample \
|
||||
/usr/include/aarch64-linux-gnu/cjson.h /usr/include/cjson; do
|
||||
cp_r "$h" "$CTX/sysinc/"
|
||||
done
|
||||
cp_r /usr/include/*.h "$CTX/sysinc/"
|
||||
}
|
||||
|
||||
CTX="/tmp/case_ctx_${FAMILY}_vpu"
|
||||
rm -rf "$CTX"; mkdir -p "$CTX/src" "$CTX/usr/hobot" "$CTX/py_case" "$CTX/usrlib_root"
|
||||
cp -a /usr/hobot/lib "$CTX/usr/hobot/"
|
||||
cp -a /usr/hobot/include "$CTX/usr/hobot/"
|
||||
cp "$SCRIPT_DIR/selftest.sh" "$CTX/selftest.sh"
|
||||
assemble || { rm -rf "$CTX"; exit 0; }
|
||||
expand_syslib_deps
|
||||
rt_base="$RUNTIME_BASE"
|
||||
|
||||
tag="case_vpu_${FAMILY}:$(date +%y%m%d_%H%M%S)"
|
||||
echo "[INFO] 构建 $tag (上下文: $CTX, $(du -sh $CTX | cut -f1))"
|
||||
docker build --build-arg BASE="$APP_BASE_TAG" --build-arg RUNTIME="$rt_base" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" -t "$tag" "$CTX"
|
||||
echo "[OK] $tag 构建完成"
|
||||
28
examples/vpu/any/run.sh
Executable file
28
examples/vpu/any/run.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# vpu 单元案例镜像运行自测: 精确设备透传启动, 镜像内自测入口判定,
|
||||
# 日志穿透写入本目录 output/
|
||||
set -e
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "$SCRIPT_DIR/../../common/app_base_common.sh"
|
||||
|
||||
OUT_DIR="$SCRIPT_DIR/output"; mkdir -p "$OUT_DIR"
|
||||
MOUNT_ARGS="$(build_common_mount_args)"
|
||||
DEVICE_ARGS="$(build_device_args vpu)" || { echo "[skip] vpu 单元定义错误"; exit 0; }
|
||||
|
||||
repo="case_vpu_${FAMILY}"
|
||||
tag="$(resolve_tag "$repo")"
|
||||
if [ -z "$tag" ]; then
|
||||
echo "[skip] 无 $repo 时间 tag 镜像 (先运行本目录 build.sh)"; exit 0
|
||||
fi
|
||||
tag="$repo:$tag"
|
||||
log="$OUT_DIR/${FAMILY}.log"
|
||||
timeout 300 docker run --rm --name "case-vpu-$FAMILY" \
|
||||
$MOUNT_ARGS $DEVICE_ARGS \
|
||||
-e HB_DNN_USER_DEFINED_L2M_SIZES="${HB_DNN_USER_DEFINED_L2M_SIZES:-6:6:6:6}" \
|
||||
"$tag" > "$log" 2>&1 || true
|
||||
verdict=$(grep -oE 'TEST (PASS|FAIL|SKIP).*' "$log" | tail -1)
|
||||
verdict="${verdict:-TEST FAIL (no verdict)}"
|
||||
printf "%-8s %s (日志: output/${FAMILY}.log)\n" "vpu" "$verdict"
|
||||
# SKIP(硬件缺席) 不计失败
|
||||
[ "${verdict#TEST SKIP}" != "$verdict" ] && exit 0
|
||||
[ "${verdict#TEST PASS}" != "$verdict" ]
|
||||
30
examples/vpu/any/selftest.sh
Normal file
30
examples/vpu/any/selftest.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
# VPU/JPU 单元案例自测: sample_codec 一个案例同时验证两个硬件单元
|
||||
# 路径1 (VPU): 默认配置 H264 编码, 走 /dev/vpu* (strace 实证)
|
||||
# 路径2 (JPU): codec_type=3 JPEG 编码, 走 /dev/jpu* (strace 实证)
|
||||
# 通过判据: 两条路径 15 秒内各编码不少于 50 帧
|
||||
cd /opt/test
|
||||
|
||||
# --- 路径1: VPU (H264) ---
|
||||
OUT1=$(timeout 20 ./sample_codec 2>&1)
|
||||
RC1=$?
|
||||
F1=$(echo "$OUT1" | grep -oE 'frame=[[:space:]]*[0-9]+' | tail -1 | grep -oE '[0-9]+')
|
||||
F1=${F1:-0}
|
||||
echo "[VPU/H264] 15 秒编码 ${F1} 帧 (rc=$RC1)"
|
||||
|
||||
# --- 路径2: JPU (JPEG) ---
|
||||
sed -e 's/^codec_type = 0$/codec_type = 3/' \
|
||||
-e 's/^output = 1920x1080_30fps.h264$/output = out.jpg/' \
|
||||
codec_config.ini > jpeg_config.ini
|
||||
OUT2=$(timeout 20 ./sample_codec -f jpeg_config.ini 2>&1)
|
||||
RC2=$?
|
||||
F2=$(echo "$OUT2" | grep -oE 'frame=[[:space:]]*[0-9]+' | tail -1 | grep -oE '[0-9]+')
|
||||
F2=${F2:-0}
|
||||
echo "[JPU/JPEG] 15 秒编码 ${F2} 帧 (rc=$RC2)"
|
||||
|
||||
if [ "$F1" -ge 50 ] && [ "$F2" -ge 50 ]; then
|
||||
echo "TEST PASS (vpu+jpu: h264 ${F1} frames via VPU, jpeg ${F2} frames via JPU)"
|
||||
exit 0
|
||||
fi
|
||||
echo "TEST FAIL (vpu/jpu: h264=${F1} jpeg=${F2})"
|
||||
exit 1
|
||||
@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
# ============================================================
|
||||
# Docker 一键安装脚本
|
||||
# 适用平台: Ubuntu 22.04 (ARM64 / aarch64 / x86_64)
|
||||
# 适用平台: Ubuntu 22.04 / 24.04 (ARM64 / aarch64 / x86_64)
|
||||
# 自动检测系统版本并适配
|
||||
# 说明: 通过 Ubuntu 官方 ports 源安装 docker.io
|
||||
# 不修改 eth0 网络配置, 不需要重启
|
||||
# ============================================================
|
||||
@ -21,12 +22,38 @@ warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
|
||||
error() { echo -e "${RED}[ERROR]${NC} $*"; }
|
||||
die() { error "$*"; exit 1; }
|
||||
|
||||
# ---------- 检测 Ubuntu 版本 ----------
|
||||
# 标准 Ubuntu: VERSION_ID 即为 22.04 / 24.04
|
||||
# RDK OS: VERSION_ID 是自身版本 (如 V5.1.0), 需从 VERSION_CODENAME
|
||||
# 识别 Ubuntu 基础版本 (如 "rdk os noble" -> noble -> 24.04)
|
||||
OS_VERSION_ID=$(sed -n 's/^VERSION_ID=//p' /etc/os-release 2>/dev/null | tr -d '"' | tail -1)
|
||||
UBUNTU_CODENAME=$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release 2>/dev/null | tr -d '"' | tail -1)
|
||||
|
||||
UBUNTU_VER=""
|
||||
case "$OS_VERSION_ID" in
|
||||
22.04|24.04) UBUNTU_VER="$OS_VERSION_ID" ;;
|
||||
*)
|
||||
case "$UBUNTU_CODENAME" in
|
||||
*jammy*) UBUNTU_VER="22.04" ;;
|
||||
*noble*) UBUNTU_VER="24.04" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
echo " Docker 一键安装脚本 (Ubuntu 22.04 ARM64/x86_64)"
|
||||
echo " Docker 一键安装脚本 (Ubuntu ${UBUNTU_VER:-未知} ${UBUNTU_CODENAME} ARM64/x86_64)"
|
||||
echo "============================================================"
|
||||
echo ""
|
||||
|
||||
# ---------- 0. 校验 Ubuntu 版本 ----------
|
||||
info "检测 Ubuntu 版本..."
|
||||
if [ -n "$UBUNTU_VER" ]; then
|
||||
success "Ubuntu 基础版本: ${UBUNTU_VER} (${UBUNTU_CODENAME}) ✓"
|
||||
else
|
||||
warn "无法识别 Ubuntu 基础版本 (VERSION_ID=${OS_VERSION_ID:-未知}, CODENAME=${UBUNTU_CODENAME:-未知}), 本脚本针对 22.04/24.04 验证, 继续执行但可能出现问题"
|
||||
fi
|
||||
|
||||
# ---------- 验证函数 (必须在调用前定义) ----------
|
||||
verify_docker() {
|
||||
echo ""
|
||||
@ -230,6 +257,20 @@ else
|
||||
success "iptable_raw 模块可用 ✓"
|
||||
fi
|
||||
|
||||
# 检查内核是否有 ip6table_raw 模块
|
||||
# RT 内核同样可能没有编译 ip6table_raw,
|
||||
# Docker 28+ 会向 IPv6 raw 表写 DROP 规则, 模块缺失时 dockerd 启动报:
|
||||
# "can't initialize ip6tables table `raw': Table does not exist"
|
||||
# 解决方案: 在 daemon.json 加 "ip6tables": false 关闭 IPv6 防火墙规则
|
||||
# (仅在模块缺失时写入, 不改变模块可用板子的默认行为)
|
||||
IP6TABLES_LINE=""
|
||||
if ! modprobe ip6table_raw 2>/dev/null && ! lsmod | grep -q '^ip6table_raw'; then
|
||||
warn "内核缺少 ip6table_raw 模块, 将在 daemon.json 设置 \"ip6tables\": false"
|
||||
IP6TABLES_LINE=' "ip6tables": false,'
|
||||
else
|
||||
success "ip6table_raw 模块可用 ✓"
|
||||
fi
|
||||
|
||||
cat > /etc/docker/daemon.json <<EOF
|
||||
{
|
||||
"registry-mirrors": [
|
||||
@ -237,6 +278,7 @@ cat > /etc/docker/daemon.json <<EOF
|
||||
],
|
||||
"dns": ["114.114.114.114", "223.5.5.5"],
|
||||
"allow-direct-routing": ${ALLOW_DIRECT_ROUTING},
|
||||
${IP6TABLES_LINE}
|
||||
"log-driver": "json-file",
|
||||
"log-opts": {
|
||||
"max-size": "10m",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user