Coder Social home page Coder Social logo

filmarini / firmware-hls Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cms-l1tk/firmware-hls

0.0 0.0 0.0 34.84 MB

HLS implementation of the tracklet pattern reco modules of the Hybrid tracking chain

Shell 1.64% C++ 57.69% Python 14.34% C 9.27% Tcl 9.06% VHDL 8.02%

firmware-hls's Introduction

firmware-hls : HLS implementation of the hybrid L1 track firmware

Repo directory contents:

  • IntegrationTests/ : HDL top files and simulations for chains of HLS modules and memories.
  • TestBenches/ : Test bench code.
  • TrackletAlgorithm/ : Algo source code.
  • TrackQuality/ : BDT Track Quality specific source code.
  • emData/ : .dat files with input/output test-bench data (corresponding to memory between algo steps) + .tab files of data for LUTs used internally by algos.
  • project/ : .tcl scripts to create HLS project, compile & run code.

Most of the following directions will reference Vivado HLS and the corresponding vivado_hls command. You may use Vitis HLS instead by replacing all of the vivado_hls commands with vitis_hls.

An HLS project can be generated by running tcl file with Vivado/Vitis HLS in firmware-hls/project/ directory. e.g. To do so for the ProjectionRouter:

    vivado_hls -f script_PR.tcl

This would create a project directory <project> ("projrouter" in case of the above example). The project name is defined in the tcl script. To open the project in GUI:

    vivado_hls -p <project>

Running chains (illustrated for IR to TB skinny chain)

  1. cd IntegrationTests/ReducedConfig/IRtoTB/script/
  2. vivado_hls -f compileHLS.tcl (makes HLS IP cores).
  3. vivado -mode batch -source makeProject.tcl (creates Vivado project).
  4. vivado -mode batch -source runSim.tcl (runs Vivado simulation, which writes data output from chain to dataOut/*.txt).
  5. python ../../common/script/CompareMemPrintsFW.py -p -s (compares .txt files in emData and dataOut/ writing comparison to dataOut/*_cmp.txt. Uses Python 3.).
  6. vivado -mode batch -source ../../common/script/synth.tcl (runs synthesis, writes utilization & timing reports to current directory).
  7. vivado -mode batch -source ../../common/script/impl.tcl (runs implementation, writes utilization & timing reports to current directory). N.B. This step is optional, and not required for code validation.

Track Quality Specific Instructions

In the TrackQuality directory first run:

    setupEnv.sh environment.yml Install

This will install a miniconda python environment under the Install dir within the TrackQuality dir (or manually install the packages listed in environment.yml if you have an existing conda install)

Then run:

    source env.sh

to setup the python environment

To first download the testbench .dat files and the python saved model and then generate the track quality HLS from a python saved model format run:

    run_TQ_coniferconversion.sh

Once run this will generate the 2 HLS files for the track quality firmware (BDT.h and parameters.h) and a reference datafile that will be compared with the csim output. To run the track quality csim, synth etc.. :

    vivado_hls -f script_TQ.tcl

Which generates the project folder trackquality

Note on .dat testbench files: These testbench files will be generated by the CMSSW emulation. Two files are created, one hls_feature.dat used by conifer to run its own predictions and one hls_hex.dat that contains full 96-bit tttrack_trackwords for the track quality HLS to predict on. This CMSSW emulation relies on changes to the TTTrack_trackword dataformat and as such is currently not part of the cms-L1TK CMSSW fork. A development version of CMSSW to generate the test files is found here: https://github.com/Chriisbrown/cmssw/tree/cbrown-TrackQualityMemfiles

Format of emData/ files.

.dat files (test bench input/output data)

These have test data corresponding to the contents of the memories between algo steps. Their data format is explained in https://twiki.cern.ch/twiki/bin/view/CMS/HybridDataFormat .

e.g. AllStubs*.dat contains one row per stub: "stub_number stub_coords_(binary)[r|z|phi|...] ditto_but_in_hex"; StubPairs*.dat contains one row per stub pair "pair_number stub_index_in_allstubs_mem_(binary)[innerLayer|outerLayer] ditto_but_in_hex.

File naming convention: "L3" or "D5" indicate barrel or disk number; "PHIC" indicates 3rd course phi division given layer of nonant.

Some of the files are large, so not stored directly in git. These are automatically downloaded when any of the scripts in the project/ directory are executed within Vivado/Vitis HLS.

.tab files

These correspond to LUT used internally by the algo steps.

Corresponding CMSSW L1 track emulation

Full configuration

The files that are downloaded by emData/download.sh were created by the CMSSSW L1 track emulation, with the the following recipe (adapted from the L1TrackSoftware TWiki).

cmsrel CMSSW_12_0_0_pre4
cd CMSSW_12_0_0_pre4/src/
cmsenv
git cms-checkout-topic -u cms-L1TK:fw_synch_220523

A few configuration changes were made in order to output test vectors and lookup tables and adjust truncation. This required editing parameter values in L1Trigger/TrackFindingTracklet/interface/Settings.h to match the following excerpts:

//IR should be set to 108 to match the FW for the summer chain, but ultimately should be at 156
    std::unordered_map<std::string, unsigned int> maxstep_{{"IR", 108},  //IR will run at a higher clock speed to handle
                                                                         //input links running at 25 Gbits/s
                                                           //Set to 108 to match firmware project 240 MHz clock//--- These used to create files needed by HLS code.
    bool writeMem_{true};     //If true will print out content of memories (between algo steps) to files
    bool writeTable_{true};   //If true will print out content of LUTs to files
    bool writeConfig_{true};  //If true will print out the autogenerated configuration as filesbool writeHLSInvTable_{true};  //Write out tables of drinv and invt in tracklet calculator for HLS module

Then compilation was done with the usual command:

scram b -j8

The maximum number of events in L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py was set to 100:

process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(100))
…

Also, in the same file, the algorithm was set to HYBRID_NEWKF:

# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
# 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
# (Or legacy algos 'TMTT' or 'TRACKLET').
L1TRKALGO = 'HYBRID_NEWKF'

Finally, the emulation was run with:

cd L1Trigger/TrackFindingTracklet/test/
cmsRun L1TrackNtupleMaker_cfg.py

Reduced configuration

The files for the reduced configuration used for the summer/skinny chain were created by first running the full configuration as described above. Then, the project_generation_scripts repo was cloned, the wiring files for the full configuration were copied, the makeReducedConfig.py script was run, and the wiring files for the reduced configuration were copied back into the release:

cd $CMSSW_BASE/../
git clone https://github.com/cms-L1TK/project_generation_scripts.git
cd project_generation_scripts/
cp $CMSSW_BASE/src/L1Trigger/TrackFindingTracklet/data/LUTs/*.dat ./
./makeReducedConfig.py --no-graph
cp -fv reduced_*.dat $CMSSW_BASE/src/L1Trigger/TrackFindingTracklet/data/
cd -

The algorithm was changed to HYBRID_REDUCED:

# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
# 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
# (Or legacy algos 'TMTT' or 'TRACKLET').
L1TRKALGO = 'HYBRID_REDUCED'

Finally, the emulation was rerun as for the full configuration:

cmsRun L1TrackNtupleMaker_cfg.py

Configuration with combined modules

The files for the configuration with combined modules (i.e., the TrackletProcessor and MatchProcessor) were created with the same recipe as for the full configuration described above, except the combined_ parameter was also set to true in L1Trigger/TrackFindingTracklet/interface/Settings.h:

bool combined_{true};  // use combined TP (TE+TC) and MP (PR+ME+MC) configuration

Compilation was done again with the usual command:

cd $CMSSW_BASE/src/
scram b -j8
cd -

The algorithm was reset to HYBRID_NEWKF:

# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
# 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
# (Or legacy algos 'TMTT' or 'TRACKLET').
L1TRKALGO = 'HYBRID_NEWKF'

Finally, the emulation was rerun as before:

cmsRun L1TrackNtupleMaker_cfg.py

Barrel-only configuration (very preliminary)

The files for the barrel-only configuration were created by first running the full configuration as described above. Then, the head of the barrel_config branch of the emulation was checked out and compiled:

cd $CMSSW_BASE/src/
git ls-files -m | xargs git checkout --
git cms-checkout-topic -u cms-L1TK:e5047997b33dc6cfb1d7ce35aa34dfc56c0fe9bf
scram b -j8
cd -

The project_generation_scripts repo was cloned, the wiring files for the full configuration were copied, the makeBarrelConfig.py script was run, and the wiring files for the barrel-only configuration were copied back into the release:

cd $CMSSW_BASE/../
git clone https://github.com/cms-L1TK/project_generation_scripts.git
cd project_generation_scripts/
cp $CMSSW_BASE/src/L1Trigger/TrackFindingTracklet/data/LUTs/*.dat ./
./makeBarrelConfig.py
cp -fv barrel_*.dat $CMSSW_BASE/src/L1Trigger/TrackFindingTracklet/data/
cd -

The algorithm was reset to HYBRID_NEWKF:

# Set L1 tracking algorithm:
# 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit).
# 'HYBRID_NEWKF' (baseline, 4par fit, with bit-accurate KF emulation),
# 'HYBRID_REDUCED' to use the "Summer Chain" configuration with reduced inputs.
# (Or legacy algos 'TMTT' or 'TRACKLET').
L1TRKALGO = 'HYBRID_NEWKF'

Finally, the emulation was rerun as before:

cmsRun L1TrackNtupleMaker_cfg.py

Continuous Integration (CI)

Purpose: Automatically run SW quality checks and build the HLS projects (csim, csynth, cosim, and export) for a PR to the master.

In order to keep the GitHub repository public we use GitHub Actions and GitLab CI/CD:

  • GitHub Actions uses a public runner, the workflow is defined in .github/workflows/github_CI.yml
  • GitHub Actions mirrors the repository to GitLab and runs GitLab CI/CD
  • GitLab CI/CD uses a private runner (lnxfarm327.colorado.edu) and performs the SW quality checks and the HLS builds as defined in .gitlab-ci.yml
    • SW quality checks are based on clang-tidy (llvm-toolset-7.0) and are defined in .clang-tidy and .clang-format very similar to CMSSW
    • HLS builds are using Vivado HLS (or Vitis HLS) and are defined in the script files of the project folder
    • Results (logs and artifacts) of the SW quality checks and HLS builds can be found here https://gitlab.cern.ch/cms-l1tk/firmware-hls/pipelines
    • The default behavior blocks a stage (e.g. Hls-build) when a previous stage (e.g. Quality-check) failed
  • GitHub Actions pulls the GitLab CI/CD status and the pass/fail outcome

Use CI for Personal Branch

  • Add your branch name to the "on:" section of .github/workflows/GitLab_CI.yml
    • In the "push:" subsection to trigger CI on each push, e.g. "branches: [feat_CI,<your_branch_name>]" and/or
    • in the "pull_request:" subsection to trigger CI on each PR, e.g. "branches: [master,<your_branch_name>]"

firmware-hls's People

Contributors

pwittich avatar aehart avatar zctao avatar mzientek avatar robertglein avatar meisonlikesicecream avatar djcranshaw avatar tomalin avatar ksung25 avatar bryates avatar sseifeln avatar carriganm95 avatar rzoucern avatar jasonfan393 avatar chriisbrown avatar emyrclement avatar filmarini avatar aryd avatar ryanm124 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.