Skip to content

chenlongos/ACT-Runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ACT Runtime — SG2002 TPU 多语言推理引擎

围绕 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% 对齐


API 对比

C(最精简,11KB)

#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);

C++(RAII,类型安全)

#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());

Python(最简洁,无需编译)

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)

Rust(async + camera)

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.md

板端运行

export 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

参考

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors