Skip to content

Commit 6292633

Browse files
authored
Merge pull request #73 from thesps/conifer
Update conifer docs
2 parents f7f4e03 + 1c29041 commit 6292633

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

content/inference/conifer.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,33 @@
1414

1515
## Emulation in CMSSW
1616

17-
All L1T algorithms require bit-exact emulation for performance studies and validation of the hardware system. For conifer this is provided with a single header file at `L1Trigger/Phase2L1ParticleFlow/interface/conifer.h`. The user must also provide the BDT JSON file exported from the conifer Python tool for their model. JSON loading in CMSSW uses the `nlohmann/json` external.
17+
All L1T algorithms require bit-exact emulation for performance studies and validation of the hardware system. For conifer this is provided with a [single header file](https://github.com/thesps/conifer/blob/master/conifer/backends/cpp/include/conifer.h) that is a CMSSW external `conifer.h`. The user must also provide the BDT JSON file exported from the conifer Python tool for their model. Usually the model JSON file should be saved at [`cms-data`](https://github.com/cms-data). JSON loading in CMSSW uses the `nlohmann/json` external.
1818

1919
Both the conifer FPGA firmware and C++ emulation use Xilinx's arbitrary precision types for fixed-point arithmetic (`hls` external of CMSSW). This is cheaper and faster in the FPGA fabric than floating-point types. An important part of the model preparation process is choosing the proper fixed-point data types to avoid loss of performance compared to the trained model. Input preprocessing, in particular scaling, can help constrain the input variables to a smaller numerical range, but may also have a hardware cost to implement. In C++ the arbitrary precision types are specified like: `ap_fixed<width, integer, rounding mode, saturation mode>`.
2020

2121
Minimal preparation from Python:
22-
```
22+
```python
2323
import conifer
2424
model = conifer. ... # convert or load a conifer model
2525
# e.g. model = conifer.converters.convert_from_xgboost(xgboost_model)
2626
model.save('my_bdt.json')
2727
```
2828

29-
CMSSW C++ user code:
29+
Include the conifer and HLS external in your package's `BuildFile.xml`:
30+
31+
```xml
32+
<use name="conifer"/>
33+
<use name="hls"/>
3034
```
35+
36+
CMSSW C++ user code:
37+
```c++
3138
// include the conifer emulation header file
32-
#include "L1Trigger/Phase2L1ParticleFlow/interface/conifer.h"
39+
#include "conifer.h"
40+
// include the HLS types header file
41+
#include "ap_fixed.h"
3342

34-
... model setup
43+
// ... model setup
3544
// define the input/threshold and score types
3645
// important: this needs to match the firmware settings for bit-exactness!
3746
// note: can use native types like float/double for development/debugging
@@ -42,7 +51,7 @@ typedef ap_fixed<12,3,AP_RND_CONV,AP_SAT> score_t;
4251
// 'true' to use balanced add-tree score aggregation (needed for bit-exactness)
4352
bdt = conifer::BDT<input_t, score_t, true>("my_bdt.json");
4453

45-
... inference
54+
// ... inference
4655
// prepare the inputs, vector length same as model n_features
4756
std::vector<input_t> inputs = ...
4857
// run inference, scores vector length same as model n_classes (or 1 for binary classification/regression)

0 commit comments

Comments
 (0)