围绕 SG2002 TPU (cvitek cv181x) 的 C / C++ / Python / Rust 四语言推理运行时。
所有语言共用同一个硬件和 API(libcviruntime.so → /dev/cvi-tpu0),仅语言层封装不同。
| 语言 | 二进制 | TPU Forward | 代码行数 | 编译 | 适用 |
|---|---|---|---|---|---|
| C | 11KB | 39.6ms | ~250 | gcc -O3 |
嵌入式/最小开销 |
| C++ | 15KB | 40.0ms | ~150 | g++ -O3 |
平衡性能+抽象 |
| Python | 15KB | 40.0ms | ~120 | 无需编译 | 开发/调试/原型 |
| Rust | 860KB | 41ms | ~500 | cargo build |
摄像头管线/安全 |
YOLOv8n tennis, conf=0.969, box=(261,263,371,377) — 四语言检出 100% 对齐
#include "sg2002_tpu.h"
tpu_t *tp = tpu_open("model.cvimodel");
uint8_t *data = tpu_load_int8("image.int8", &size);
tpu_infer(tp, data, size);
int n = tpu_decode(tp->out_ptr, tp->out_N, 0.5f, 0.45f, dets, 32);
tpu_close(tp);
free(data);#include "sg2002_tpu.hpp"
tpu::Engine engine("model.cvimodel");
auto data = tpu::load_int8("image.int8");
engine.fill_input(data);
engine.forward();
auto dets = tpu::decode_nms((float*)engine.output_ptr(),
engine.output_N(), engine.output_C());from sg2002_tpu import TPUEngine, decode_nms, load_int8
engine = TPUEngine("model.cvimodel")
data, _ = load_int8("image.int8")
dets = decode_nms(engine(data), engine.out_shape)let mut model = open_model("model.cvimodel")?;
let detections = model.infer(&frame, config)?;ACT-Runtime/
├── README.md # 本文件
├── c/ # C 实现
│ ├── sg2002_tpu.h # 头文件
│ ├── sg2002_tpu.c # 引擎实现
│ ├── main.c # CLI 入口
│ └── build.sh # 编译脚本
├── cpp/ # C++ 实现
│ ├── sg2002_tpu.hpp # 头文件
│ ├── sg2002_tpu.cpp # 引擎实现
│ ├── main.cpp # CLI 入口
│ └── Makefile # 构建
├── python/ # Python 实现
│ └── sg2002_tpu/
│ ├── __init__.py # 包入口
│ ├── engine.py # TPU 引擎 (ctypes)
│ ├── decode.py # NMS 解码器
│ └── cli.py # 命令行
├── rust/ # Rust 实现
│ └── README.md # 构建说明
└── benchmark_report.md # 性能测试报告
| 组件 | 版本 |
|---|---|
| 工具链 | Xuantie V3.4.0 (riscv64-unknown-linux-musl) |
| TPU SDK | tpu-sdk-sg200x (cvitek) |
| 模型 | yolov8n_tennis_v2.cvimodel (cv181x, v1.4.0) |
| 平台 | SG2002 (LicheeRV Nano) |
# C
cd c && bash build.sh
# C++
cd cpp && make TPU_SDK=/path/to/tpu-sdk-sg200x TPU_LIBS=/path/to/libs
# Python — 无需编译,直接部署
cp -r python/sg2002_tpu /mnt/sde2/
# Rust — 见 rust/README.mdexport LD_LIBRARY_PATH=/akars_tennis/lib:/lib # C / C++
export PYTHONHOME=/ LD_PRELOAD=/lib/libffi.so LD_LIBRARY_PATH=/lib:/akars_tennis/lib # Python
# C
./yolo_tpu_c /images/tennis-ball-close.int8 --bench
# C++
./yolo_tpu_infer /images/tennis-ball-close.int8 --bench
# Python
python3 -m sg2002_tpu /images/tennis-ball-close.int8 --bench 10- chenlongos/ACT-Runtime — 本仓库
- jiangyuyue111/sg2002_yolo_inference — 完整三系统项目
- Maxye112/sg2002-act-starryos — 辰龙 Proj57
- BattiestStone4/akars — Rust TPU 驱动