Skip to content
Snippets Groups Projects
Commit 83995c44 authored by ssummers's avatar ssummers
Browse files

Add MLATL1T_DIR env variable. Update part3 exercise instructions. Update...

Add MLATL1T_DIR env variable. Update part3 exercise instructions. Update emulator wrapper for real model
parent 09723f75
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,8 @@ HLS4ML Emulator Class
class L1TMLDemo_emulator_v1 : public hls4mlEmulator::Model {
private:
static const int N_INPUT=2; // TODO update this to real model
// Note: these need to match the defined model
static const int N_INPUT=26;
static const int N_OUTPUT=1;
input_t _input[N_INPUT];
result_t _result[N_OUTPUT];
......@@ -32,7 +33,7 @@ public:
virtual void read_result(std::any result) {
// copy result
result_t *result_p = std::any_cast<result_t*>(result);
result_p[0] = _result;
*result_p = _result;
}
};
......
In this exercise you will be guided through the steps to create, compile, and run the emulator of the hls4ml model you trained in part 2. The code in these steps should be executed from the command line on `lxplus` after doing `source setup.sh` from this `cms_mlatl1t_tutorial`.
When developing your own hls4ml NN emulators, you should compile and run your model emulator locally before delivering it to `cms-hls4ml`.
## Prerequisite
......@@ -8,8 +11,8 @@ You will need the HLS for the model of part 2.
Copy the NN-specific part of the hls4ml project to the `cms-hls4ml` repo. We _don't_ copy `ap_types` since we'll reference them from the externals.
```shell
[ ! -d part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN ] && mkdir part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN
cp -r L1TMLDemo/firmware/{*.h,*.cpp,weights,nnet_utils} part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN
[ ! -d $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN ] && mkdir $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN
cp -r $MLATL1T_DIR/part2/L1TMLDemo_v1/firmware/{*.h,*.cpp,weights,nnet_utils} $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN
```
## 2.
......@@ -19,7 +22,7 @@ As of `hls4ml` `0.8.1`, when run outside of Vivado HLS, the C++ code loads the w
This one liner will replace the `#define` that would cause the weights to be loaded from txt files with one that will load them from the header files when we compile instead.
```shell
find part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/#ifndef __SYNTHESIS__/#ifdef __HLS4ML_LOAD_TXT_WEIGHTS__/'
find $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/#ifndef __SYNTHESIS__/#ifdef __HLS4ML_LOAD_TXT_WEIGHTS__/'
```
## 3.
......@@ -27,7 +30,7 @@ find part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN \( -type d -name .git -prune \)
`make` the hls4ml emulator interface shared object
```shell
cd part3/cms-hls4ml/hls4mlEmulatorExtras
cd $MLATL1T_DIR/part3/cms-hls4ml/hls4mlEmulatorExtras
make
mkdir lib64
mv libemulator_interface.so lib64
......@@ -38,10 +41,39 @@ mv libemulator_interface.so lib64
`make` the `L1TMLDemo` model shared object
```shell
cd part3/cms-hls4ml/L1TMLDemo
cd $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo
make
```
*Note* you might benefit from adding `-g` to `CXXFLAGS` to compile with debugging while developing.
The Makefile line would change to `CXXFLAGS := -O3 -fPIC -std=$(CPP_STANDARD) -g`.
## 5.
CMSSW emulator...
\ No newline at end of file
`scram build` compile the CMSSW code
```shell
cd $CMSSW_BASE/src
scram b -j8
```
## 6.
Copy the `L1TMLDemo` model shared object to the CMSSW area.
```shell
mkdir $CMSSW_BASE/src/L1Trigger/L1TMLDemo/data
cp $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1.so $CMSSW_BASE/src/L1Trigger/L1TMLDemo/data
```
## 7.
Run the test config!
```shell
cd $CMSSW_BASE/src/L1Trigger/L1TMLDemo/test
cmsRun demoL1TMLNtuple.py
```
*Note* when developing your own models, you may unfortunately run into segmentation violations while developing. The most common reason is that the input and output data type set in the producer mismatch the types used by the model emulator. In this emulator workflow, this causes a runtime error rather than a compile time error.
......@@ -3,6 +3,7 @@
CMSSW_VERSION=CMSSW_13_3_0_pre3
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export MLATL1T_DIR=$SCRIPT_DIR
# create CMSSW area if it doesn't exist, and cmsenv
[ ! -d CMSSW_13_3_0_pre3 ] && echo "ML@L1T Setup: cmsrel $CMSSW_VERSION" && \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment