Skip to content

Commit

Permalink
MP cleanup 220208 + MC fix (cms-sw#133)
Browse files Browse the repository at this point in the history
* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Some updates to MP to converge with HLS code

* Further clenup of the MP code

* More cleanup -removal of hardcoded numbers

* Further cleanup

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Some updates to MP to converge with HLS code

* Further clenup of the MP code

* More cleanup -removal of hardcoded numbers

* Further cleanup

* Fixes to the MC to allow full agreement with HLS

* Added a comment header and pipeline description

* Added comment about MC iterations

Co-authored-by: Thomas Schuh <thomas.schuh@stfc.ac.uk>
Co-authored-by: Anders <aryd@cern.ch>
  • Loading branch information
3 people authored and tomalin committed Jun 10, 2022
1 parent 899b15c commit 948bbb5
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 229 deletions.
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace trklet {
void addOutput(MemoryBase* memory, std::string output) override;
void addInput(MemoryBase* memory, std::string input) override;

void execute(double phioffset);
void execute(unsigned int iSector, double phioffset);

std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > mergeMatches(
std::vector<CandidateMatchMemory*>& candmatch);
Expand Down
61 changes: 44 additions & 17 deletions L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/****************************************************************
* MatchEngineUnit (MEU) is a single instance of the MatchEngine
* section of the MatchProcessor (MP)
*
* Manual pipelining is implemented to properly emulate the HLS
* implementation (required to meet II=1)
*
* A total of `nMatchEngines_` MEUs are used in the MP
****************************************************************/
#ifndef L1Trigger_TrackFindingTracklet_interface_MatchEngineUnit_h
#define L1Trigger_TrackFindingTracklet_interface_MatchEngineUnit_h

Expand All @@ -18,7 +27,7 @@ namespace trklet {

class MatchEngineUnit {
public:
MatchEngineUnit(bool barrel, unsigned int layerdisk, const TrackletLUT& luttable);
MatchEngineUnit(const Settings& settings, bool barrel, unsigned int layerdisk, const TrackletLUT& luttable);

~MatchEngineUnit() = default;

Expand All @@ -35,9 +44,7 @@ namespace trklet {
bool usesecondMinus,
bool usesecondPlus,
bool isPSseed,
Tracklet* proj,
bool print,
int imeu);
Tracklet* proj);

bool empty() const { return candmatches_.empty(); }

Expand All @@ -47,32 +54,40 @@ namespace trklet {

std::pair<Tracklet*, const Stub*> peek() const { return candmatches_.peek(); }

Tracklet* currentProj() const { return proj_; }

bool idle() const { return idle_; }

bool active() const { return !idle_ || goodpair_ || !empty(); }

//needed for consistency with HLS FW version ("_" vs "__" indicating different pipelining stages)
bool have_() const { return havepair_; }
bool active() const { return !idle_ || good__ || good___ || !empty(); }

void setAlmostFull();

void setimeu(int imeu) {
imeu_ = imeu;
}

void setprint(bool print) {
print_ = print;
}

void reset();

unsigned int rptr() const { return candmatches_.rptr(); }
unsigned int wptr() const { return candmatches_.wptr(); }

void step(bool print);
void step();

void processPipeline();

private:

//Provide access to constants
const Settings& settings_;

VMStubsMEMemory* vmstubsmemory_;

unsigned int nrzbins_;
unsigned int rzbin_;
unsigned int phibin_;
int shift_;
int imeu_;

unsigned int istub_;
unsigned int iuse_;
Expand All @@ -83,7 +98,7 @@ namespace trklet {
int projfinephi_;
std::vector<std::pair<unsigned int, unsigned int>> use_;
bool isPSseed_;
Tracklet* proj_;
Tracklet *proj_;

bool idle_;

Expand All @@ -95,13 +110,25 @@ namespace trklet {
//LUT for bend consistency with rinv
const TrackletLUT& luttable_;

//Pipeline variables
std::pair<Tracklet*, const Stub*> tmppair_;
bool goodpair_;
bool havepair_;
//Various manually pipelined variables
//Each _ represents a layer of pipelining
//e.g., good__ is set and one iteration later good___ is updated
VMStubME vmstub__, vmstub___;
bool isPSseed__, isPSseed___;
bool good__, good___;
int projfinerz__, projfinerz___;
int projfinephi__, projfinephi___;
int projrinv__, projrinv___;
Tracklet *proj__, *proj___;

//save the candidate matches
CircularBuffer<std::pair<Tracklet*, const Stub*>> candmatches_;

//debugging help
int imeu_;
bool print_;


};

}; // namespace trklet
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/interface/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ namespace trklet {
{"TC", 108},
{"PR", 108},
{"ME", 108},
{"MC", 104},
//NOTE: The MC is set to 108, but `mergedepth`
//removes 3 iterations to emulate the delay
//due to the HLS priority encoder
{"MC", 108},
{"TB", 108},
{"MP", 108},
{"TP", 108},
Expand Down
13 changes: 11 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "DataFormats/Math/interface/deltaPhi.h"

#include <filesystem>
#include <algorithm>

using namespace std;
using namespace trklet;
Expand Down Expand Up @@ -113,15 +114,23 @@ void MatchCalculator::addInput(MemoryBase* memory, string input) {
throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input;
}

void MatchCalculator::execute(double phioffset) {
void MatchCalculator::execute(unsigned int iSector, double phioffset) {
unsigned int countall = 0;
unsigned int countsel = 0;

//bool print = getName() == "MC_L4PHIC" && iSector == 3;

Tracklet* oldTracklet = nullptr;

std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > mergedMatches = mergeMatches(matches_);

for (unsigned int j = 0; j < mergedMatches.size(); j++) {
// Number of clock cycles the pipeline in HLS takes to process the projection merging to
// produce the first projectio
unsigned int mergedepth = 3;

unsigned int maxProc = std::min(settings_.maxStep("MC") - mergedepth, (unsigned int)mergedMatches.size());

for (unsigned int j = 0; j < maxProc; j++) {
if (settings_.debugTracklet() && j == 0) {
edm::LogVerbatim("Tracklet") << getName() << " has " << mergedMatches.size() << " candidate matches";
}
Expand Down
Loading

0 comments on commit 948bbb5

Please sign in to comment.