Build & Test Embedded AI Apps with AMD Vitis
In this article
This guide walks through building and testing embedded AI applications using AMD Vitis tools, covering the setup, compilation, and hardware-in-the-loop verification workflow. You'll learn how to go from a trained model to a running application on an AMD adaptive SoC, and how to validate its performance and correctness.
What You'll Need
- AMD Vitis Unified Software Platform (2023.2 or newer) installed on a Linux or Windows machine.
- AMD Vitis AI tool suite (available as a separate download that integrates with Vitis).
- A supported AMD evaluation board (e.g., Kria KV260, VCK190, or Alveo card) with the corresponding board support package.
- A trained deep learning model in a standard format (PyTorch, TensorFlow, ONNX).
- Host machine with at least 16 GB RAM and 50 GB free disk space.
- Optional: Docker installed for the Vitis AI container (recommended for cross-compilation).
Step-by-Step
- Set up the Vitis environment. Source the Vitis environment script:
source /opt/Xilinx/Vitis/2023.2/settings64.sh(adjust path to your install). Also source the Vitis AI environment if installed separately:source /opt/Xilinx/Vitis-AI/setup.sh. - Create a new Vitis application project. Launch Vitis from the terminal (
vitis) and choose File → New → Application Project. Select your target platform (e.g., the KV260 base platform) and give the project a name. - Prepare your AI model. If you have a trained model, convert it to a quantized ONNX or TensorFlow model using the Vitis AI Quantizer. For example, with PyTorch, use the
vai_q_pytorchtool:vai_q_pytorch quantize --model model.pth --output_dir quantized. - Compile the model for the target DPU. Use the Vitis AI Compiler to generate an instruction stream for the Deep Learning Processor Unit (DPU). For example:
vai_c_xir --xmodel quantized_model.xmodel --arch /path/to/arch.json --output_dir ./compiled. The architecture file depends on your DPU version (e.g., DPUCZDX8G for KV260). - Add the compiled model to your Vitis project. In Vitis, right-click on the project's src folder and select Import Sources. Add the compiled
.xmodelfile and any necessary label files. - Write the host application. In the src folder, create a C++ or Python application that uses the Vitis AI Runtime (VART) API to load the model, preprocess input images, run inference, and postprocess results. A minimal C++ example:
#include <vart/runner.hpp> // ... load xmodel, get input/output tensors, run runner->execute_async()If using Python, install the Vitis AI Python package and usefrom vitis_ai_library import Runner. - Build the application. In Vitis, select the project and click the build hammer icon. The build system will compile the host code and link against the VART libraries. Ensure the board support package includes the DPU driver.
- Deploy to the board. Connect the board via Ethernet and set up the target root filesystem (the Vitis AI pre-built SD card image is recommended). Copy the compiled
.xmodeland the executable to the board usingscpor a shared folder. - Run the application on the board. Execute the binary on the board's Linux shell. For example:
./app.exe model.xmodel input.jpg. Monitor the console output for inference results and timing. - Test and validate. Compare the output against expected results (e.g., classification accuracy on a test set). Measure latency and throughput using the timing functions built into your code or external profiling tools like
perfon the board. - Iterate for performance. If performance is insufficient, consider optimizing the model (e.g., pruning), adjusting the DPU configuration (e.g., number of cores), or using the Vitis HLS to create custom accelerators for bottlenecks.
Common Mistakes
- Mismatched DPU architecture: Using a compiler architecture file that doesn't match the DPU on your board leads to runtime errors. Always verify the arch JSON corresponds to your board's DPU version.
- Forgetting to quantize: Running a float model on the DPU is unsupported; the model must be quantized to 8-bit or lower. Skipping quantization causes compilation errors or incorrect results.
- Incorrect input preprocessing: The model expects specific input normalization (e.g., mean/std). If your preprocessing differs from the training pipeline, accuracy will drop significantly.
- Not setting up the board's environment: The board needs the Vitis AI runtime libraries and DPU driver installed. Using a bare Linux image without the BSP will fail to load the model.
- Hardcoding file paths: Using absolute paths that exist only on the host machine will break on the target. Use relative paths or environment variables.
Tips
- Use the Vitis AI Docker container for a consistent build environment; it includes all necessary tools and dependencies.
- Start with a simple model (like ResNet-50) to verify the toolchain before moving to custom models.
- Leverage the Vitis AI Profiler to identify bottlenecks in the inference pipeline.
- Keep the model input size small (e.g., 224x224) to reduce latency and memory usage.
- Use the board's serial console for debugging if Ethernet fails.
Troubleshooting
- Compilation fails with "undefined reference to vart::Runner": Ensure you have linked the VART library (
-lvart-runner) and included the correct include paths. - Runtime error "Cannot open xmodel": Check that the .xmodel file is present on the board and that the path is correct. Also verify the file was compiled for the correct DPU.
- Inference results are garbage: Re-check the input preprocessing (mean/std, channel order) and ensure the model was quantized correctly. Also verify the output tensor shape matches your expectations.
- Board hangs during inference: This often indicates a power or thermal issue. Check the board's power supply and cooling. Reduce the clock frequency of the DPU via the device tree if needed.
- Performance is much slower than expected: Ensure the DPU is actually being used (not falling back to CPU). Check the Vitis AI profiler output to see if the DPU is idle. Also check if the model is too large for the DPU's memory, causing thrashing.
Frequently Asked Questions
Do I need to know FPGA programming to use Vitis AI?
No, the Vitis AI flow abstracts the FPGA design. You work with the DPU as a pre-built accelerator, so you only need C++/Python and basic Linux skills.
Can I use a TensorFlow model directly?
Yes, you can use TensorFlow models, but they must be converted to a quantized format (e.g., via Vitis AI Quantizer) and then compiled to an .xmodel.
What is the difference between Vitis and Vitis AI?
Vitis is the unified software platform for all AMD adaptive SoCs and FPGAs. Vitis AI is a separate tool suite specifically for AI inference, providing quantizer, compiler, and runtime.
How do I choose the right DPU architecture file?
The architecture file (arch.json) is provided in the Vitis AI installation under arch/DPUCZDX8G/ or similar, and it must match the DPU version on your board. Check your board's documentation.
Can I run multiple models on the same board?
Yes, you can load multiple .xmodel files and run them sequentially or concurrently, depending on the DPU's resources. The VART runtime supports multiple runners.
Is there a way to test without physical hardware?
Yes, you can use the Vitis AI simulator for functional testing, but it is slower and does not give accurate performance numbers. For performance, you need the actual board or a cloud-based FPGA instance.