hrt_model_exec 工具介绍

hrt_model_exec 是一个模型执行工具,可直接在开发板上评测模型的推理性能、获取模型信息。 一方面可以让您拿到模型时实际了解模型真实性能; 另一方面也可以帮助您了解模型可以做到的速度极限,对于应用调优的目标极限具有指导意义。 hrt_model_exec 工具源码位于发布物的 samples/ucp_tutorial/tools/hrt_model_exec 路径下。结构如下所示:

├── include # 头文件 ├── src # 工具源码 ├── build.sh # 编译脚本 ├── build_x86.sh # 编译产生x86工具 ├── build_aarch64.sh # 编译产生aarch64 Linux系统工具 ├── build_qnx.sh # 编译产生aarch64 QNX系统工具 ├── CMakeLists.txt ├── README.md ├── script │ └── run_hrt_model_exec.sh # aarch64工具运行脚本原件,编译后会下载至output_shared_S100_aarch64/script目录 └── script_x86 └── run_hrt_model_exec.sh # x86工具运行脚本原件,编译后会下载至output_shared_S100_x86/script_x86目录

运行流程

构建方式

ucp_tutorial/tools/hrt_model_exec 目录下有预先配置好的编译脚本 build.sh,选项 -a x86-a aarch64-a aarch64-qnx 分别支持三种编译方式,您可以使用该脚本并指定编译选项进行编译。 此外,目录中也包含了 build_aarch64.shbuild_qnx.shbuild_x86.sh 三个编译脚本,分别对应了三个编译选项,使用这三个脚本进行编译与使用 build.sh 脚本并指定编译选项等效。

# 构建Linux板端运行工具 bash -ex build_aarch64.sh # 构建x86端运行工具 bash -ex build_x86.sh # 构建QNX板端运行工具 bash -ex build_qnx.sh

运行方式

以Linux环境为例,构建板端运行工具后,将生成 output_shared_S100_aarch64 文件夹。 您可以将文件夹复制到板端环境中并执行 output_shared_S100_aarch64/script/run_hrt_model_exec.sh 来使用该工具。

构建x86端运行工具后,将生成 output_shared_S100_x86 文件夹。 您可以在x86端直接执行 output_shared_S100_x86/script_x86/run_hrt_model_exec.sh 来使用该工具。

run_hrt_model_exec.sh 脚本分为设置环境变量和获取模型信息并推理模型两部分。

# 设置环境变量 # arch代表架构类型,aarch64或x86 arch=aarch64 bin=../$arch/bin/hrt_model_exec lib=../$arch/lib/ export LD_LIBRARY_PATH=${lib}:${LD_LIBRARY_PATH} # 获取模型信息 ${bin} model_info --model_file=xxx.hbm # 推理模型 ${bin} infer --model_file=xxx.hbm --input_file=xxx.bin # 获取模型性能 ${bin} perf --model_file=xxx.hbm --frame_count=200
Note

运行前需要修改 run_hrt_model_exec.sh 相应参数,以确保模型和输入文件正确。您还可以灵活使用其他参数来使用更多功能。

使用场景

hrt_model_exec工具支持三种使用场景:查看模型信息、模型推理、模型性能分析。