Conifer translates trained Boosted Decision Trees to FPGA firmware for extreme low latency inference.
Conifer is on the Python Package Index, so install it like:
pip install conifer
Building FPGA firmware requires tools from Xilinx - a High Level Synthesis tool and Vivado, depending on the choice of backend. We recommend the most recent version Vivado ML and Vitis HLS 2022.2.
Using the C++ backends requires JSON header files from here. Clone or download the repository, and set the environment variable JSON_ROOT
to the JSON include path. Xilinx's arbitrary precision header files (e.g. ap_fixed.h
) are required to use these type for emulation. They are automatically found if you have source the Xilinx HLS toolchain, but you can also find them here. If using the C++ backend without a Vivado installation, clone or download Xilinx's repository, and set the environment variable XILINX_HLS
to the include path.
Conifer converts from popular BDT training frameworks, and can emit code projects in different FPGA languages.
Available converters:
Available backends:
$PATH
)See our paper in JINST: "Fast inference of Boosted Decision Trees in FPGAs for particle physics".
Conifer originated as a development for hls4ml, and is developed under the Fast Machine Learning Lab.
View the API reference at the conifer homepage
from sklearn.ensemble import GradientBoostingClassifier
# Train a BDT
clf = GradientBoostingClassifier().fit(X_train, y_train)
# Create a conifer config dictionary
cfg = conifer.backends.xilinxhls.auto_config()
# Change the bit precision (print the config to see everything modifiable)
cfg['Precision'] = 'ap_fixed<12,4>'
# Convert the sklearn model to a conifer model
model = conifer.converters.convert_from_sklearn(clf, cfg)
# Write the HLS project and compile the C++-Python bridge
model.compile()
# Run bit-accurate prediction on the CPU
y_hls = model.decision_function(X)
y_skl = clf.decision_function(X)
# Synthesize the model for the target FPGA
model.build()
Check the examples directory for examples to get started with, and the BDT part of the hls4ml tutorial.
The conifer Forest Processing Unit (FPU) is a flexible IP for fast BDT inference on FPGAs. One FPU can be configured to perform inference of different BDTs without rebuilding the IP or bitstream.
git clone https://github.com/thesps/conifer
git clone https://github.com/nlohmann/json
git clone https://github.com/Xilinx/HLS_arbitrary_Precision_Types
JSON_ROOT
and XILINX_AP_INCLUDE
as the include
directory in them respectively e.g.
export XILINX_AP_INCLUDE=$(pwd)/HLS_arbitrary_Precision_Types/include
export JSON_ROOT=$(pwd)/json/include
cd conifer
pip install -r dev_requirements.txt
export PYTHONPATH="$(pwd):${PYTHONPATH}" && python examples/sklearn_to_cpp.py
pytest tests/test_multiclass.py
pytest
The following are some applications using conifer
either in production or R&D. If you think your own use case should be featured here, please get in touch.
The ATLAS experiment at CERN's Large Hadron Collider is currently using conifer
to better reconstruct events with tau leptons. See this talk at the Fast Machine Learning 2023 workshop.
xgboost
Vitis HLS
J. Gonski et al, Embedded FPGA Developments in 130nm and 28nm CMOS for Machine Learning in Particle Detector Readout, 2024, arXiv:2404.17701v1
A team from Stanford and SLAC have shown that a tiny Decision Tree model running in an eFPGA at the periphery of a particle tracking detector frontend ASIC can be used to filter data from pile-up events.
scikit-learn
HLS
Alsharari M et al. Efficient Implementation of AI Algorithms on an FPGA-based System for Enhancing Blood Vessel Segmentation. doi:10.21203/rs.3.rs-4351485/v1.
The authors demonstrate methods to perform performing image segmentation to identify blood vessels in a proposed surgical imaging device. A GBDT, deployed to a Kria SoM with conifer
, achieved the best FPS with segmentation performance competitive with U-Net models.
ONNX
(catboost
)Vitis HLS
Apart from the source code and binaries of the Forest Processing Unit (FPU), conifer
is licensed under Apache v2. The FPU source code and binaries are licensed under the CERN-OHL-P v2 or later.