tigris codegen
Generate backend-specific C source code from a compiled .tgrs plan. The generated code embeds the plan data as a C array, providing an alternative to loading .tgrs at runtime from a flash partition.
Usage
tigris codegen PLAN [OPTIONS]Options
| Flag | Type | Required | Description |
|---|---|---|---|
PLAN | path | yes | Compiled .tgrs plan file |
-b, --backend | choice | no | Kernel backend: reference, cmsis-nn, esp-nn (default: reference) |
-o, --output | path | no | Output C file path |
Examples
Generate reference C code:
tigris codegen model.tgrs -o model.cGenerate for ESP-NN backend:
tigris codegen model.tgrs --backend esp-nn -o model_esp.cGenerate for CMSIS-NN backend:
tigris codegen model.tgrs --backend cmsis-nn -o model_cmsis.cWhen to Use Codegen vs. Loading .tgrs
There are two ways to deploy a compiled plan to your device:
Loading .tgrs at runtime
The plan is stored in a flash partition and loaded at runtime with tigris_plan_load().
Advantages:
- Swap models without recompiling firmware by reflashing the plan partition
- Smaller firmware binary (plan is separate)
- Multiple models can share the same firmware
When to use: Devices with a flash partition table, applications that need model updates in the field, development/iteration workflows.
# Compile the plan
tigris compile model.onnx -m 256K -o model.tgrs
# Flash to partition
scripts/flash_plan.sh model.tgrsCodegen (plan embedded in firmware)
The plan is compiled into a C source file and linked directly into the firmware binary.
Advantages:
- Simpler build with no flash partition management
- Single binary contains everything
- Works on targets without partition table support
When to use: Simple deployments, single-model devices, targets with no flash partition support, CI/CD pipelines that produce a single firmware artifact.
# Compile the plan, then generate C code
tigris compile model.onnx -m 256K -o model.tgrs
tigris codegen model.tgrs --backend cmsis-nn -o model.c
# Add model.c to your firmware buildComparison
| .tgrs loading | Codegen | |
|---|---|---|
| Plan location | Flash partition | Compiled into firmware |
| Model swap | Reflash partition only | Recompile firmware |
| Build complexity | Partition table + flash script | Add .c to build |
| Firmware size | Smaller (plan separate) | Larger (plan embedded) |
| Flash partition needed | Yes | No |