Skip to content

Commit

Permalink
Memory cleanup (cms-sw#98)
Browse files Browse the repository at this point in the history
* Cleanup of writing leading 0x in memories

* Cleanup of obsolote comment

* Change order of input links to match VMRouter expectation

* Add support for debugging

* Remove one pipelining step to match HLS

* Determine the PS vs 2S in disks same way as we do in HLS

* Some cleanup

* Correction to LUT code

* Comment out printout

* Ran scram build code-format

* Update comment about IR steps

* Cleanup of obsolote comment

* Remove one pipelining step to match HLS

* Determine the PS vs 2S in disks same way as we do in HLS

* Correction to LUT code

* Ran scram build code-format
  • Loading branch information
aryd authored and tomalin committed May 31, 2022
1 parent 323c8ea commit a921921
Show file tree
Hide file tree
Showing 29 changed files with 183 additions and 210 deletions.
9 changes: 4 additions & 5 deletions L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ namespace trklet {

bool idle() const { return idle_; }

bool active() const { return !idle_ || goodpair_ || goodpair__ || !empty(); }
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 have__() const { return havepair__; }

void reset();

Expand Down Expand Up @@ -90,9 +89,9 @@ namespace trklet {
const TrackletLUT& luttable_;

//Pipeline variables
std::pair<Tracklet*, const Stub*> tmppair_, tmppair__;
bool goodpair_, goodpair__;
bool havepair_, havepair__;
std::pair<Tracklet*, const Stub*> tmppair_;
bool goodpair_;
bool havepair_;

//save the candidate matches
CircularBuffer<std::pair<Tracklet*, const Stub*>> candmatches_;
Expand Down
5 changes: 4 additions & 1 deletion L1Trigger/TrackFindingTracklet/interface/MemoryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ namespace trklet {
// extended is the seeding for displaced tracks
void initSpecialSeeding(unsigned int pos, bool& overlap, bool& extra, bool& extended);

//Used for a hack below due to MAC OS case sensitiviy problem for files
//Used for a hack below due to MAC OS case insensitiviy problem for files
void findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr);

void openFile(bool first, std::string dirName, std::string filebase);

static size_t find_nth(const std::string& haystack, size_t pos, const std::string& needle, size_t nth);

//Format index position in hex
static std::string hexstr(unsigned int index);

protected:
std::string name_;
unsigned int iSector_;
Expand Down
7 changes: 5 additions & 2 deletions L1Trigger/TrackFindingTracklet/interface/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ namespace trklet {

double bendcut(int ibend, int layerdisk, bool isPSmodule) const {
if (layerdisk >= N_LAYER && (!isPSmodule))
layerdisk += (N_LAYER - 1);
layerdisk += N_DISK;
double bendcut = bendcut_[layerdisk][ibend];
if (bendcut <= 0.0)
std::cout << "bendcut : " << layerdisk << " " << ibend << " " << isPSmodule << std::endl;
Expand All @@ -429,7 +429,7 @@ namespace trklet {
double bendcutte(int ibend, int layerdisk, bool isPSmodule) const { return bendcut(ibend, layerdisk, isPSmodule); }

double bendcutme(int ibend, int layerdisk, bool isPSmodule) const {
//FIXME temporary fix until phiprojderdisk bits adjusted. But requires coordinatin with HLS
//Should understand why larger cut needed in disks
double fact = (layerdisk < N_LAYER) ? 1.0 : 1.8;
return fact * bendcut(ibend, layerdisk, isPSmodule);
}
Expand Down Expand Up @@ -754,9 +754,12 @@ namespace trklet {
unsigned int maxstepoffset_{0};

//Number of processing steps for one event (108=18TM*240MHz/40MHz)

//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", 156}, //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

{"VMR", 108},
{"TE", 107},
{"TC", 108},
Expand Down
4 changes: 1 addition & 3 deletions L1Trigger/TrackFindingTracklet/interface/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ namespace trklet {
}

inline double rinv(double phi1, double phi2, double r1, double r2) {
if (r2 <= r1) { //FIXME can not form tracklet should not call function with r2<=r1
return 20.0;
}
assert(r1 < r2); //Can not form tracklet should not call function with r2<=r1

double dphi = phi2 - phi1;
double dr = r2 - r1;
Expand Down
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace trklet {
void addOutput(MemoryBase* memory, std::string output) override;
void addInput(MemoryBase* memory, std::string input) override;

void execute();
void execute(unsigned int iSector);

private:
//0-5 are the layers and 6-10 are the disks
Expand Down
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ void AllInnerStubsMemory::writeStubs(bool first, unsigned int iSector) {

for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub = stubs_[j]->strinner();
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub << " " << hexFormat(stub) << endl;
out_ << hexstr(j) << " " << stub << " " << hexFormat(stub) << endl;
}
out_.close();
}
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ void AllProjectionsMemory::writeAP(bool first, unsigned int iSector) {
for (unsigned int j = 0; j < tracklets_.size(); j++) {
string proj =
(layer_ > 0) ? tracklets_[j]->trackletprojstrlayer(layer_) : tracklets_[j]->trackletprojstrdisk(disk_);
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << proj << " " << trklet::hexFormat(proj) << endl;
out_ << hexstr(j) << " " << proj << " " << trklet::hexFormat(proj) << endl;
}
out_.close();

Expand Down
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ void AllStubsMemory::writeStubs(bool first, unsigned int iSector) {

for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub = stubs_[j]->str();
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub << " " << hexFormat(stub) << endl;
out_ << hexstr(j) << " " << stub << " " << hexFormat(stub) << endl;
}
out_.close();
}
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ void CandidateMatchMemory::writeCM(bool first, unsigned int iSector) {
projindex = (1 << 7) - 1;
}
tmp.set(projindex, 7, true, __LINE__, __FILE__);
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << tmp.str() << "|" << stubid << " " << trklet::hexFormat(tmp.str() + stubid) << endl;
out_ << hexstr(j) << " " << tmp.str() << "|" << stubid << " " << trklet::hexFormat(tmp.str() + stubid) << endl;
}
out_.close();

Expand Down
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ void CleanTrackMemory::writeCT(bool first, unsigned int iSector) {
out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;

for (unsigned int j = 0; j < tracks_.size(); j++) {
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec << " ";
out_ << tracks_[j]->trackfitstr() << " " << trklet::hexFormat(tracks_[j]->trackfitstr());
out_ << hexstr(j) << " " << tracks_[j]->trackfitstr() << " " << trklet::hexFormat(tracks_[j]->trackfitstr());
out_ << "\n";
}
out_.close();
Expand Down
4 changes: 1 addition & 3 deletions L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ void DTCLinkMemory::writeStubs(bool first, unsigned int iSector) {
FPGAWord ldcode(lcode, 2, true);

string stub = stubs_[j]->str() + "|" + ldcode.str() + "|1";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
out_ << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl;
}
out_.close();
}
Expand Down
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ void FullMatchMemory::writeMC(bool first, unsigned int iSector) {

for (unsigned int j = 0; j < matches_.size(); j++) {
string match = (layer_ > 0) ? matches_[j].first->fullmatchstr(layer_) : matches_[j].first->fullmatchdiskstr(disk_);
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << match << " " << trklet::hexFormat(match) << endl;
out_ << hexstr(j) << " " << match << " " << trklet::hexFormat(match) << endl;
}
out_.close();

Expand Down
5 changes: 1 addition & 4 deletions L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ void InputLinkMemory::writeStubs(bool first, unsigned int iSector) {

for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub = stubs_[j]->str();
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
out_ << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl;
}
out_.close();
}
Expand Down
16 changes: 14 additions & 2 deletions L1Trigger/TrackFindingTracklet/src/MatchEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,22 @@ void MatchEngine::execute(unsigned int iSector) {
//Read vmstub memory and extract data fields
const VMStubME& vmstub = vmstubs_->getVMStubMEBin(rzbin, istubtmp);

bool isPSmodule = vmstub.isPSmodule();

int stubfinerz = vmstub.finerz().value();

bool isPSmodule = false;

if (barrel_) {
isPSmodule = layerdisk_ < N_PSLAYER;
} else {
if (layerdisk_ < N_LAYER + 2) {
isPSmodule = ((rzbin & 7) < 3) || ((rzbin & 7) == 3 && stubfinerz <= 3);
} else {
isPSmodule = ((rzbin & 7) < 3) || ((rzbin & 7) == 3 && stubfinerz <= 2);
}
}

assert(isPSmodule == vmstub.isPSmodule());

int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S;

int deltaphi = projfinephi - vmstub.finephi().value();
Expand Down
37 changes: 13 additions & 24 deletions L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, const Trac
barrel_ = barrel;
layerdisk_ = layerdisk;
goodpair_ = false;
goodpair__ = false;
havepair_ = false;
havepair__ = false;
}

void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
Expand All @@ -29,7 +27,7 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
bool usesecondPlus,
bool isPSseed,
Tracklet* proj,
bool) {
bool print) {
vmstubsmemory_ = vmstubsmemory;
idle_ = false;
nrzbins_ = nrzbins;
Expand Down Expand Up @@ -61,30 +59,26 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory,
//Even when you init a new projection you need to process the pipeline
//This should be fixed to be done more cleanly - but require synchronizaton
//with the HLS code
if (goodpair__) {
candmatches_.store(tmppair__);
if (goodpair_) {
if (print)
std::cout << "Init have pair" << std::endl;
candmatches_.store(tmppair_);
}

havepair__ = havepair_;
goodpair__ = goodpair_;
tmppair__ = tmppair_;

havepair_ = false;
goodpair_ = false;
}

void MatchEngineUnit::step(bool) {
void MatchEngineUnit::step(bool print) {
bool almostfull = candmatches_.nearfull();

if (goodpair__) {
assert(havepair__);
candmatches_.store(tmppair__);
if (goodpair_) {
if (print)
std::cout << "Step have pair" << std::endl;
assert(havepair_);
candmatches_.store(tmppair_);
}

havepair__ = havepair_;
goodpair__ = goodpair_;
tmppair__ = tmppair_;

havepair_ = false;
goodpair_ = false;

Expand Down Expand Up @@ -141,7 +135,6 @@ void MatchEngineUnit::step(bool) {
}

// Detailed printout for comparison with HLS code
bool print = false;
if (print)
edm::LogVerbatim("Tracklet") << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " "
<< vmstub.stubindex().value() << " "
Expand Down Expand Up @@ -175,22 +168,18 @@ void MatchEngineUnit::reset() {
idle_ = true;
istub_ = 0;
goodpair_ = false;
goodpair__ = false;
havepair_ = false;
havepair__ = false;
}

int MatchEngineUnit::TCID() const {
if (!empty()) {
return peek().first->TCID();
}

if (idle_ && !havepair_ && !havepair__) {
if (idle_ && !havepair_) {
return 16383;
}
if (havepair__) {
return tmppair__.first->TCID();
}

if (havepair_) {
return tmppair_.first->TCID();
}
Expand Down
11 changes: 6 additions & 5 deletions L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) {
tmpProj.use(1, 1),
tmpProj.isPSseed(),
tmpProj.proj(),
print && (iME == 0));
print);
addedProjection = true;
} else {
matchengines_[iME].step(print && iME == 0);
matchengines_[iME].step(print);
}
}

Expand Down Expand Up @@ -343,8 +343,9 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) {
(proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) &
((1 << nrbits_) - 1);

int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >>
(proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) &
int phiprojder = proj->proj(layerdisk_).fpgaphiprojder().value();

int phiderindex = (phiprojder >> (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) &
((1 << nphiderbits_) - 1);

int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0;
Expand Down Expand Up @@ -429,7 +430,7 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) {
}
}

bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool, unsigned int) {
bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep) {
const L1TStub* stub = fpgastub->l1tstub();

if (layerdisk_ < N_LAYER) {
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/TrackFindingTracklet/src/MemoryBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <set>
#include <filesystem>
#include <sstream>

using namespace trklet;
using namespace std;
Expand Down Expand Up @@ -106,3 +107,9 @@ size_t MemoryBase::find_nth(const string& haystack, size_t pos, const string& ne
return found_pos;
return find_nth(haystack, found_pos + 1, needle, nth - 1);
}

std::string MemoryBase::hexstr(unsigned int index) {
std::ostringstream oss;
oss << "0x" << std::setfill('0') << std::setw(2) << hex << index << dec;
return oss.str();
}
2 changes: 1 addition & 1 deletion L1Trigger/TrackFindingTracklet/src/Sector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void Sector::executeVMR() {
i->execute();
}
for (auto& i : VMRCM_) {
i->execute();
i->execute(isector_);
}
}

Expand Down
6 changes: 2 additions & 4 deletions L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ void StubPairsMemory::writeSP(bool first, unsigned int iSector) {
for (unsigned int j = 0; j < stubs_.size(); j++) {
string stub1index = stubs_[j].first.stub()->stubindex().str();
string stub2index = stubs_[j].second.stub()->stubindex().str();
out_ << "0x";
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub1index << "|" << stub2index << " " << trklet::hexFormat(stub1index + stub2index) << endl;
out_ << hexstr(j) << " " << stub1index << "|" << stub2index << " " << trklet::hexFormat(stub1index + stub2index)
<< endl;
}
out_.close();

Expand Down
4 changes: 1 addition & 3 deletions L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ void StubTripletsMemory::writeST(bool first, unsigned int iSector) {
string stub1index = stubs1_[j]->stubindex().str();
string stub2index = stubs2_[j]->stubindex().str();
string stub3index = stubs3_[j]->stubindex().str();
out_ << std::setfill('0') << std::setw(2);
out_ << hex << j << dec;
out_ << " " << stub1index << "|" << stub2index << "|" << stub3index << endl;
out_ << hexstr(j) << " " << stub1index << "|" << stub2index << "|" << stub3index << endl;
}
out_.close();

Expand Down
Loading

0 comments on commit a921921

Please sign in to comment.