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

FlagTypeRequiredDescription
PLANpathyesCompiled .tgrs plan file
-b, --backendchoicenoKernel backend: reference, cmsis-nn, esp-nn (default: reference)
-o, --outputpathnoOutput C file path

Examples

Generate reference C code:

tigris codegen model.tgrs -o model.c

Generate for ESP-NN backend:

tigris codegen model.tgrs --backend esp-nn -o model_esp.c

Generate for CMSIS-NN backend:

tigris codegen model.tgrs --backend cmsis-nn -o model_cmsis.c

When 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.tgrs

Codegen (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 build

Comparison

.tgrs loadingCodegen
Plan locationFlash partitionCompiled into firmware
Model swapReflash partition onlyRecompile firmware
Build complexityPartition table + flash scriptAdd .c to build
Firmware sizeSmaller (plan separate)Larger (plan embedded)
Flash partition neededYesNo