How to compile ONNX to FPGA

Check whether your trained model can run on an AMD FPGA, then take the generated Verilog through simulation and Vivado synthesis.

1. Upload an ONNX model

Use your own .onnx export with weights stored in the file, or download the tiny ONNX example. The example is a single matrix multiply with input shape [1, 4] and output shape [1, 2].

When the free FPGA model analyzer is open, select the file and click Analyze my model. If Fish asks for a symbolic input size, enter the dimension name and size as name=value, such as height=224. The example already has fixed dimensions.

2. Read the FPGA compatibility report

Start with Blockers. If Fish flags an unsupported operation or shape, check whether you can change the export and run the analysis again. A valid ONNX file can still have operations the compiler cannot map to hardware.

Compute counts multiply-accumulate operations per inference. The tiny example uses eight and rounds to 0.0 G MACs in the web report. Fits on gives a first estimate of which boards can hold the model. The compile checks feasibility for the board you choose.

3. Compile ONNX to Verilog

Choose your target board when ordering the compile. The build includes encrypted AXI Verilog, model weights, a bit-exact testbench with test vectors, and a Vivado synthesis script and clock constraint.

Run the supplied testbench to check the RTL outputs against Fish’s INT8 reference. To assess the effect of quantization on model accuracy, compare that reference with the original ONNX model on representative inputs.

In a local Fish build targeting the AMD Kria KV260, the downloadable example passed all 16 bit-exact test vectors in RTL simulation.

Run the supplied Vivado script from the build directory to synthesize the accelerator. Review the utilization and timing reports before integrating the core into your board design.

Troubleshoot an ONNX export

The analyzer asks for an input size. Supply the value for the shape you will deploy. If your application uses more than one shape, analyze each deployment shape you plan to support.

The report flags an unsupported node. Start with the operation or shape named under Blockers. If you change the export, compare its outputs with the original on representative inputs before trying the compiler again.

The board estimate looks promising. Use the generated Vivado reports to check resource usage and timing at your target clock. Measure inference on the board to account for memory and the rest of the system.

Open the FPGA model analyzer