Overview
The hls4ml API provides tools for converting machine learning models to FPGA firmware. This reference covers all major modules and functions.Main Modules
Converters
Convert models from Keras, PyTorch, and ONNX
Model
Core model graph and layer management
Backends
FPGA backend implementations
Utils
Configuration and utility functions
Quick Start
Here’s a basic example of converting a Keras model:Core Functions
Model Conversion
convert_from_keras_model()- Convert Keras modelsconvert_from_pytorch_model()- Convert PyTorch modelsconvert_from_onnx_model()- Convert ONNX modelsconvert_from_config()- Convert from YAML configuration
Configuration
create_config()- Create backend configurationconfig_from_keras_model()- Generate config from Keras modelconfig_from_pytorch_model()- Generate config from PyTorch modelconfig_from_onnx_model()- Generate config from ONNX model
Model Operations
model.compile()- Compile the generated projectmodel.predict()- Run inferencemodel.build()- Synthesize with HLS toolsmodel.write()- Write project to disk
Module Structure
Architecture
Conversion Flow
- Parse - Extract model architecture and weights
- Transform - Convert to internal representation (ModelGraph)
- Optimize - Apply optimization passes
- Generate - Produce HLS C++ code
- Build - Synthesize with backend tools
ModelGraph
TheModelGraph is the central data structure representing your model:
- Stores layers as nodes in a directed graph
- Manages data flow between layers
- Applies optimization transformations
- Generates backend-specific code
Type System
hls4ml uses a sophisticated type system for precision:FixedPrecisionType- Fixed-point types (e.g.,ap_fixed<16,6>)IntegerPrecisionType- Integer types (e.g.,ap_int<8>)FloatPrecisionType- Floating-point typesUnspecifiedPrecisionType- Auto-inferred precision
Next Steps
Keras Conversion
Learn about Keras model conversion
PyTorch Conversion
Learn about PyTorch model conversion
Model API
Explore the ModelGraph API
Configuration
Configure your conversion
