tiny_bench.h 概览¶
tiny_bench.h 是 TinyBench 的统一入口头文件,聚合:
tiny_bench_config.h— 编译期配置- 类型系统枚举
tiny_type_t - 工具函数签名
tiny_tool_fn - 数据槽与工具的 API 声明
类型系统 tiny_type_t¶
每个数据槽和工具都带一个类型标签,运行时校验确保类型安全:
typedef enum {
TINY_TYPE_UNKNOWN = 0,
TINY_TYPE_F32, // float 标量
TINY_TYPE_F32_ARR, // float[] 数组
TINY_TYPE_CF32, // _Complex float
TINY_TYPE_CF32_ARR, // _Complex float[]
TINY_TYPE_SYSID_RESULT, // tiny_sysid_result_t
TINY_TYPE_DAMAGE_DETECT, // tiny_damage_detect_t
TINY_TYPE_DAMAGE_LOCATE, // tiny_damage_locate_t
TINY_TYPE_DAMAGE_ASSESS, // tiny_damage_assess_t
TINY_TYPE_U8_ARR, // uint8_t[] 裸字节
} tiny_type_t;
类型名可以通过 tiny_bench_type_name(type) 转为可读字符串(如 "f32[]"、"sysid_result")。
工具函数签名 tiny_tool_fn¶
所有 Tiny* 处理函数统一包装为此签名:
调用者负责传入类型正确的指针,类型校验在注册和流程定义时由 Orch 完成。
核心数据结构¶
数据槽 tiny_bench_slot_t¶
typedef struct {
char name[TINY_BENCH_NAME_LEN]; // 规范名称
void *data; // 指向数据的指针
size_t len; // 字节长度
tiny_type_t type; // 类型标签
bool used; // 槽位是否在用
} tiny_bench_slot_t;
工具条目 tiny_bench_tool_t¶
typedef struct {
char name[TINY_BENCH_NAME_LEN]; // 规范名称
tiny_tool_fn fn; // 函数指针
tiny_type_t in_type; // 期望输入类型
tiny_type_t out_type; // 产生输出类型
bool used; // 槽位是否在用
} tiny_bench_tool_t;
工作台 tiny_bench_t¶
typedef struct {
tiny_bench_slot_t slots[TINY_BENCH_MAX_DATA]; // 数据槽表
tiny_bench_tool_t tools[TINY_BENCH_MAX_TOOLS]; // 工具表
} tiny_bench_t;
所有表在 tiny_bench_init() 时静态分配,运行时零堆分配。
API 速览¶
初始化¶
| 函数 | 作用 |
|---|---|
tiny_bench_init(bench) | 清零所有槽位和工具表 |
数据槽管理¶
| 函数 | 作用 | 错误码 |
|---|---|---|
tiny_bench_put(bench, name, data, len, type) | 放命名数据到工作台 | OK, FULL, EXISTS |
tiny_bench_get(bench, name, &data, &len, &type) | 取命名数据 | OK, NOT_FOUND |
tiny_bench_remove(bench, name) | 删除数据槽(不释放数据) | OK, NOT_FOUND |
tiny_bench_list_data(bench, names, max) | 列出全部数据槽名 | 返回数量 |
tiny_bench_clear(bench) | 清空全部数据槽 | — |
工具注册管理¶
| 函数 | 作用 | 错误码 |
|---|---|---|
tiny_bench_register_tool(bench, name, fn, in, out) | 注册工具 | OK, FULL, EXISTS |
tiny_bench_tool_info(bench, name, &in, &out) | 查询工具类型 | OK, NOT_FOUND |
tiny_bench_get_tool_fn(bench, name, &fn, &in, &out) | 取工具函数指针+类型 | OK, NOT_FOUND |
tiny_bench_list_tools(bench, names, max) | 列出全部工具名 | 返回数量 |
工具函数¶
| 函数 | 作用 |
|---|---|
tiny_bench_type_name(type) | 将类型枚举转为可读字符串 |
错误码¶
typedef enum {
TINY_BENCH_OK = 0,
TINY_BENCH_ERR_NULL = -1, // NULL 指针参数
TINY_BENCH_ERR_NOT_FOUND = -2, // 名称不存在
TINY_BENCH_ERR_FULL = -3, // 表已满
TINY_BENCH_ERR_EXISTS = -4, // 名称已存在
TINY_BENCH_ERR_NAME_LEN = -5, // 名称超长
TINY_BENCH_ERR_TYPE = -6, // 类型不匹配
} tiny_bench_err_t;
tiny_bench_config.h 配置¶
| 宏 | 默认值 | 说明 |
|---|---|---|
TINY_BENCH_MAX_DATA | 16 | 最大命名数据槽数 |
TINY_BENCH_MAX_TOOLS | 32 | 最大注册工具数 |
TINY_BENCH_NAME_LEN | 24 | 名称最大长度(含 '\0') |
可在编译时通过 -D 覆盖。