Skip to content

Commit

Permalink
MP X-Macros (#213)
Browse files Browse the repository at this point in the history
* Updating MP

* Changes for TBHelper

* Load all MP instances

* Fully working MP

* Small fixes to match MC

* Fixed issue with L3PHIB

* Fixed MP script for TopFunctions

* Added generate_MP.py

* MP top cpp -> cc

* Run generate_MP.py in download.sh

* MP top in CombinedConfig

* Fixed gcc paths

* Added MP to Constants.h

* Improved L1 (tested PHIB and PHIC)

* Uncommented tables

* Fixed synthesis issues

* Changes to work with future SW emulation (#217)

* Removed assert

* Removed MEU params from generate_MP.py

* Delete MatchProcessor_parameters.h

* Fixes to MatchProcessor - now full agreement in L1-L6

* Updated scripts, CI should no longer fail

* Commented out custom TVs, allow MP CI to fail again

* Fixed download.sh issue

Co-authored-by: carriganm95 <carriganm95@gmail.com>
Co-authored-by: Anders Ryd <ar322@cornell.edu>
  • Loading branch information
3 people authored Jan 19, 2022
1 parent d38ab5e commit 478efa1
Show file tree
Hide file tree
Showing 15 changed files with 573 additions and 301 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ MP-quality-check:
<<: *template_quality-check
variables:
VIVADO_VERSION: "2019.2"
CLANG_TIDY_FILES: '../TestBenches/MatchProcessorL3_test.cpp ../TopFunctions/CombinedConfig/MatchProcessorTopL3.cpp'
CLANG_TIDY_FILES: '../TestBenches/MatchProcessor_test.cpp ../TopFunctions/CombinedConfig/MatchProcessorTop.cc'
TB-quality-check:
<<: *template_quality-check
variables:
Expand Down Expand Up @@ -262,8 +262,8 @@ MC-vivado-hls-build:
PROJ_NAME: "MC"
MP-vivado-hls-build:
<<: *template_hls-build
allow_failure: true
needs: ["download", "MP-quality-check"]
allow_failure: true # FIXME: remove after all errors are fixed
variables:
EXECUTABLE: 'vivado_hls'
VIVADO_VERSION: "2019.2"
Expand Down
50 changes: 49 additions & 1 deletion TestBenches/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,55 @@ X(TP_L3L4D_, "TP_L3L4D") \
X(TP_L5L6A_, "TP_L5L6A") \
X(TP_L5L6B_, "TP_L5L6B") \
X(TP_L5L6C_, "TP_L5L6C") \
X(TP_L5L6D_, "TP_L5L6D")
X(TP_L5L6D_, "TP_L5L6D") \
X(MP_D1PHIA_, "MP_D1PHIA") \
X(MP_D1PHIB_, "MP_D1PHIB") \
X(MP_D1PHIC_, "MP_D1PHIC") \
X(MP_D1PHID_, "MP_D1PHID") \
X(MP_D2PHIA_, "MP_D2PHIA") \
X(MP_D2PHIB_, "MP_D2PHIB") \
X(MP_D2PHIC_, "MP_D2PHIC") \
X(MP_D2PHID_, "MP_D2PHID") \
X(MP_D3PHIA_, "MP_D3PHIA") \
X(MP_D3PHIB_, "MP_D3PHIB") \
X(MP_D3PHIC_, "MP_D3PHIC") \
X(MP_D3PHID_, "MP_D3PHID") \
X(MP_D4PHIA_, "MP_D4PHIA") \
X(MP_D4PHIB_, "MP_D4PHIB") \
X(MP_D4PHIC_, "MP_D4PHIC") \
X(MP_D4PHID_, "MP_D4PHID") \
X(MP_D5PHIA_, "MP_D5PHIA") \
X(MP_D5PHIB_, "MP_D5PHIB") \
X(MP_D5PHIC_, "MP_D5PHIC") \
X(MP_D5PHID_, "MP_D5PHID") \
X(MP_L1PHIA_, "MP_L1PHIA") \
X(MP_L1PHIB_, "MP_L1PHIB") \
X(MP_L1PHIC_, "MP_L1PHIC") \
X(MP_L1PHID_, "MP_L1PHID") \
X(MP_L1PHIE_, "MP_L1PHIE") \
X(MP_L1PHIF_, "MP_L1PHIF") \
X(MP_L1PHIG_, "MP_L1PHIG") \
X(MP_L1PHIH_, "MP_L1PHIH") \
X(MP_L2PHIA_, "MP_L2PHIA") \
X(MP_L2PHIB_, "MP_L2PHIB") \
X(MP_L2PHIC_, "MP_L2PHIC") \
X(MP_L2PHID_, "MP_L2PHID") \
X(MP_L3PHIA_, "MP_L3PHIA") \
X(MP_L3PHIB_, "MP_L3PHIB") \
X(MP_L3PHIC_, "MP_L3PHIC") \
X(MP_L3PHID_, "MP_L3PHID") \
X(MP_L4PHIA_, "MP_L4PHIA") \
X(MP_L4PHIB_, "MP_L4PHIB") \
X(MP_L4PHIC_, "MP_L4PHIC") \
X(MP_L4PHID_, "MP_L4PHID") \
X(MP_L5PHIA_, "MP_L5PHIA") \
X(MP_L5PHIB_, "MP_L5PHIB") \
X(MP_L5PHIC_, "MP_L5PHIC") \
X(MP_L5PHID_, "MP_L5PHID") \
X(MP_L6PHIA_, "MP_L6PHIA") \
X(MP_L6PHIB_, "MP_L6PHIB") \
X(MP_L6PHIC_, "MP_L6PHIC") \
X(MP_L6PHID_, "MP_L6PHID")

#define X(module, name) module,
enum Module : size_t
Expand Down
150 changes: 0 additions & 150 deletions TestBenches/MatchProcessorL3_test.cpp

This file was deleted.

114 changes: 114 additions & 0 deletions TestBenches/MatchProcessor_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Test bench for MatchProcessor
#include "MatchProcessorTop.h"

#include <vector>
#include <algorithm>
#include <iterator>
#include <iterator>

#include "Macros.h"
#include "FileReadUtility.h"
#include "Constants.h"

// No macros can be defined from the command line in the case of C/RTL
// cosimulation, so we define defaults here.
#if !defined MODULE_
#define MODULE_ MP_L3PHIC_
#endif
#if !defined TOP_FUNC_
#define TOP_FUNC_ MatchProcessor_L3PHIC
#endif

const int nevents = 100; //number of events to run

using namespace std;

int main()
{
// Define memory patterns
const string trackletProjectionPattern = "TrackletProjections*";
const string allStubPatternarray = "AllStub*";
const string vmStubPatternarray = "VMStubs_VMSME*";
const string fullMatchPattern = "FullMatches*";

const auto stubMemType = (MODULE_ >= MP_L1PHIA_ && MODULE_ <= MP_L3PHID_) ? BARRELPS : (MODULE_ > MP_D5PHID_) ? BARREL2S : (MODULE_ >= MP_D3PHIA_) ? DISK2S : DISKPS;
const auto tprojMemType = (MODULE_ >= MP_L1PHIA_ && MODULE_ <= MP_L3PHID_) ? BARRELPS : (MODULE_ > MP_D5PHID_) ? BARREL2S : DISK;
const auto fmProjMemType = (MODULE_ >= MP_L1PHIA_ && MODULE_) ? BARREL : DISK;
TBHelper tb(std::string("MP/") + module_name[MODULE_]);

// error counts
int err = 0;

///////////////////////////
// input memories
const auto nTrackletProjections = tb.nFiles(trackletProjectionPattern);
vector<TrackletProjectionMemory<tprojMemType>> tprojarray(nTrackletProjections);
const auto nAllStub = tb.nFiles(allStubPatternarray);
vector<AllStubMemory<stubMemType>> allstub(nAllStub);
const auto nVMStubs = tb.nFiles(vmStubPatternarray);
VMStubMEMemoryCM<stubMemType, 3, 3, kNMatchEngines> vmstub;

// output memories
const auto nFullMatches = tb.nFiles(fullMatchPattern);
vector<FullMatchMemory<fmProjMemType> > fullmatcharray(nFullMatches);

// print the input files loaded
std::cout << "Loaded the input files:\n";
for (unsigned i = 0; i < nTrackletProjections; i++)
std::cout << "\t" << tb.fileNames(trackletProjectionPattern).at(i) << "\n";
for (unsigned i = 0; i < nAllStub; i++)
std::cout << "\t" << tb.fileNames(allStubPatternarray).at(i) << "\n";
for (unsigned i = 0; i < nVMStubs; i++)
std::cout << "\t" << tb.fileNames(vmStubPatternarray).at(i) << "\n";
for (unsigned i = 0; i < nFullMatches; i++)
std::cout << "\t" << tb.fileNames(fullMatchPattern).at(i) << "\n";
std::cout << std::endl;

// loop over events
cout << "Start event loop ..." << endl;
for (unsigned int ievt = 0; ievt < nevents; ++ievt) {
cout << "Event: " << dec << ievt << endl;

// read event and write to memories
auto &fin_TrackletProjections = tb.files(trackletProjectionPattern);
for (unsigned int i = 0; i < nTrackletProjections; i++)
writeMemFromFile<TrackletProjectionMemory<tprojMemType>>(tprojarray[i], fin_TrackletProjections.at(i), ievt);
auto &fin_AllStub = tb.files(allStubPatternarray);
for (unsigned int i = 0; i < nAllStub; i++)
writeMemFromFile<AllStubMemory<stubMemType>>(allstub[i], fin_AllStub.at(i), ievt);
auto &fin_VMStubs = tb.files(vmStubPatternarray);
writeMemFromFile<VMStubMEMemoryCM<stubMemType, 3, 3, kNMatchEngines>>(vmstub, fin_VMStubs.at(0), ievt);

// clear allarray, output memories before starting
for (unsigned int i = 0; i < nFullMatches; i++)
fullmatcharray[i].clear();

// bx
BXType bx = ievt;
BXType bx_out;

// Unit Under Test
TOP_FUNC_(bx, tprojarray.data(), vmstub, allstub.data(), bx_out, fullmatcharray.data());

bool truncation = false;
auto &fout_fullmatch = tb.files(fullMatchPattern);
const auto &fullmatch_names = tb.fileNames(fullMatchPattern);

// compare the computed outputs with the expected ones
for (unsigned int i = 0; i < fullmatch_names.size(); i++) {
const auto &fullmatch_name = fullmatch_names.at(i);
auto &fout = fout_fullmatch.at(i);
string label = "FullMatch " + to_string(i);
err += compareMemWithFile<FullMatchMemory<fmProjMemType> >
(fullmatcharray[i], fout, ievt, label, truncation);
}

} // end of event loop

// This is necessary because HLS seems to only return an 8-bit error count, so if err%256==0, the test bench can falsely pass
if (err > 255) err = 255;
// cout << "Module actually has " << err << " errors." << endl;
// return 0;
return err;

}
38 changes: 0 additions & 38 deletions TopFunctions/CombinedConfig/MatchProcessorTopL3.cc

This file was deleted.

16 changes: 0 additions & 16 deletions TopFunctions/CombinedConfig/MatchProcessorTopL3.h

This file was deleted.

Loading

0 comments on commit 478efa1

Please sign in to comment.