From ccff4b028abf91fbcb465515408b5bc40d695aed Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 26 Oct 2021 11:56:56 -0400 Subject: [PATCH 01/24] Updating MP --- TrackletAlgorithm/MatchProcessor_parameters.h | 138 +++++------------- project/script_MP.tcl | 67 ++++++--- 2 files changed, 84 insertions(+), 121 deletions(-) diff --git a/TrackletAlgorithm/MatchProcessor_parameters.h b/TrackletAlgorithm/MatchProcessor_parameters.h index 6c64485efc6..b828588fce8 100644 --- a/TrackletAlgorithm/MatchProcessor_parameters.h +++ b/TrackletAlgorithm/MatchProcessor_parameters.h @@ -1,115 +1,55 @@ -#ifndef TrackletAlgorithm_MatchProcessor_parameters_h -#define TrackletAlgorithm_MatchProcessor_parameters_h - -template -static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFullUnit() { - ap_uint<(1 << (2 * kNBitsBuffer))> lut; - for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { -#pragma HLS unroll - ap_uint wptr, rptr; - ap_uint<2 * kNBitsBuffer> address(i); - (rptr,wptr) = address; - auto wptr1 = wptr+1; - auto wptr2 = wptr+2; - bool result = wptr1==rptr || wptr2==rptr; - lut[i] = result; - } - return lut; +#ifndef TrackAlgorithm_MatchProcessor_parameters_h +#define TrackAlgorithm_MatchProcessor_parameters_h + +// This file contains numbers of memories and bit masks that are specific to +// each MatchProcessor and that come directly from the wiring. +// +// The validity of each of the barrel CM memories is determined by +// FMMask. The bits of this mask, from least significant to most +// significant, represent the memories in the order they are passed to +// MatchProcessor; e.g., the LSB corresponds to +// TF::L1L2. If a bit is set, the corresponding memory is +// valid, if it is not, the corresponding memory is not valid. + +// magic numbers for MP_L3PHIB +template<> constexpr uint32_t FMMask() { + return 0x9; } -template -static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFull3Unit() { - ap_uint<(1 << (2 * kNBitsBuffer))> lut; - for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { -#pragma HLS unroll - ap_uint wptr, rptr; - ap_uint<2 * kNBitsBuffer> address(i); - (rptr,wptr) = address; - ap_uint wptr1 = wptr+1; - ap_uint wptr2 = wptr+2; - ap_uint wptr3 = wptr+3; - bool result = wptr1==rptr || wptr2==rptr || wptr3==rptr; - lut[i] = result; - } - return lut; +// magic numbers for MP_L3PHIC +template<> constexpr uint32_t FMMask() { + return 0x9; } -template -static const ap_uint<(1 << (2 * kNBitsBuffer))> emptyUnit() { - ap_uint<(1 << (2 * kNBitsBuffer))> lut; - for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { -#pragma HLS unroll - ap_uint wptr, rptr; - ap_uint<2 * kNBitsBuffer> address(i); - (rptr,wptr) = address; - bool result = wptr==rptr; - lut[i] = result; - } - return lut; +// magic numbers for MP_L4PHIB +template<> constexpr uint32_t FMMask() { + return 0xB; } -template -static const ap_uint<(1 << (2 * kNBitsBuffer))> geq() { - ap_uint<(1 << (2 * kNBitsBuffer))> lut; - for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { -#pragma HLS unroll - ap_uint istub, nstubs; - ap_uint<2 * kNBitsBuffer> address(i); - (nstubs,istub) = address; - bool result = istub+1>=nstubs; - lut[i] = result; - } - return lut; +// magic numbers for MP_L5PHIB +template<> constexpr uint32_t FMMask() { + return 0x7; } -template -static const ap_uint<(1 << kNBitsBuffer)> nextUnit() { - ap_uint<(1 << kNBitsBuffer)> lut; - for(int i = 0; i < (1 << kNBitsBuffer); ++i) { -#pragma HLS unroll - ap_uint ptr(i); - lut[i] = ptr+1; - } - return lut; +// magic numbers for MP_L6PHIB +template<> constexpr uint32_t FMMask() { + return 0x5; } -template -static const ap_uint<1 << nbits> isLessThanSize() { - ap_uint<1 << nbits> tab(0); - ap_uint Max(max); - ap_uint Min(-max); - for(int i = 0; i < 1<= Min) tab[i] = 1; - } - else { - if(i < Max || i > Min) tab[i] = 1; - } - } - return tab; +// return mask bit AND mask +template constexpr bool FMMask() { + return FMMask() & (1< -static const ap_uint<1 << 2*nbits> isLessThanSize() { - ap_uint<1 << 2*nbits> tab(0); - ap_uint Max(max); - ap_uint Min(-max); - for(int i = 0; i < 1<<2*nbits; ++i) { -#pragma HLS unroll - ap_uint projphi; - ap_uint stubphi; - ap_uint address(i); - (projphi,stubphi) = address; - ap_uint result = projphi - stubphi; - if(lessThan) { - if(result <= Max || result >= Min) tab[i] = 1; - } - else { - if(result < Max || result > Min) tab[i] = 1; - } +template +static const ap_uint<1 << Seed> FMCount() { + ap_uint<1< bits(-1); + ap_uint<1< mask = bits & FMMask(); + int slot = 0; + for(int i = 0; i < Seed; ++i) { + slot += mask.range(i,i); } - return tab; + return slot; } #endif diff --git a/project/script_MP.tcl b/project/script_MP.tcl index 1ca4e0e8e74..ca830f5480d 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -1,34 +1,57 @@ -# Script to generate project for PR -# vivado_hls -f script_PR.tcl -# vivado_hls -p match_processor +# Script to generate project for MP +# vivado_hls -f script_MP.tcl +# vivado_hls -p match_calc # WARNING: this will wipe out the original project by the same name # get some information about the executable and environment source env_hls.tcl +set modules_to_test { + {MP_L3PHIC} +} +# module_to_export must correspond to the default macros set at the top of the +# test bench; otherwise, the C/RTL cosimulation will fail +set module_to_export MP_L3PHIC + # create new project (deleting any existing one of same name) -open_project -reset match_processor +open_project -reset match_calc # source files -set CFLAGS {-std=c++11 -I../TrackletAlgorithm -I../TopFunctions/CombinedConfig} -set_top MatchProcessorTopL3 -add_files ../TopFunctions/CombinedConfig/MatchProcessorTopL3.cc -cflags "$CFLAGS" -add_files -tb ../TestBenches/MatchProcessorL3_test.cpp -cflags "$CFLAGS" - -open_solution "solution1" - -# Define FPGA, clock frequency & common HLS settings. -source settings_hls.tcl +set CFLAGS {-std=c++11 -I../TrackletAlgorithm} +add_files ../TrackletAlgorithm/MatchProcessorTop.cc -cflags "$CFLAGS" +add_files -tb ../TestBenches/MatchProcessor_test.cpp -cflags "$CFLAGS" # data files -add_files -tb ../emData/MP/tables/ -add_files -tb ../emData/MP/MP_L3PHIC/ - -csim_design -mflags "-j8" -csynth_design -cosim_design -export_design -format ip_catalog -# Adding "-flow impl" runs full Vivado implementation, providing accurate resource use numbers (very slow). -#export_design -format ip_catalog -flow impl +add_files -tb ../emData/MP/ + +foreach i $modules_to_test { + set layerDisk [string range $i 3 4] + set iMP [string range $i 8 9] + set top_func [join [list "MatchProcessor_" $layerDisk "PHI" $iMP] ""] + puts [join [list "======== TESTING " $i " ========"] ""] + puts [join [list "layerDisk = " $layerDisk] ""] + puts [join [list "iMP = " $iMP] ""] + puts [join [list "top function = " $top_func] ""] + + # set macros for this module in CCFLAG environment variable + set ::env(CCFLAG) [join [list "-D \"MODULE_=" $i "_\" -D \"TOP_FUNC_=" $top_func "\""] ""] + + # run C-simulation for each module in modules_to_test + set_top $top_func + open_solution [join [list "solution_" $layerDisk $iMP] ""] + + # Define FPGA, clock frequency & common HLS settings. + source settings_hls.tcl + csim_design -mflags "-j8" + + # only run C-synthesis, C/RTL cosimulation, and export for module_to_export + if { $i == $module_to_export } { + csynth_design + cosim_design + export_design -format ip_catalog + # Adding "-flow impl" runs full Vivado implementation, providing accurate resource use numbers (very slow). + #export_design -format ip_catalog -flow impl + } +} exit From 7ac1a2c2a6b8e275f1397f2dce851838068e4494 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 26 Oct 2021 12:01:53 -0400 Subject: [PATCH 02/24] Changes for TBHelper --- TestBenches/MatchProcessor_test.cpp | 115 ++++++++++++++++++++++++++++ TrackletAlgorithm/MatchEngineUnit.h | 6 +- TrackletAlgorithm/MatchProcessor.h | 91 +++++++++++++--------- 3 files changed, 172 insertions(+), 40 deletions(-) create mode 100644 TestBenches/MatchProcessor_test.cpp diff --git a/TestBenches/MatchProcessor_test.cpp b/TestBenches/MatchProcessor_test.cpp new file mode 100644 index 00000000000..b7c0103c214 --- /dev/null +++ b/TestBenches/MatchProcessor_test.cpp @@ -0,0 +1,115 @@ +// Test bench for MatchProcessor +#include "MatchProcessorTop.h" + +#include +#include +#include +#include + +#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 allProjectionPatternarray = "AllProj*"; + const string allStubPatternarray = "AllStub*"; + 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 projMemType = (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 tprojarray(nTrackletProjections); + const auto nAllProjections = tb.nFiles(allProjectionPatternarray); + vector> allproj(nAllProjections); + const auto nAllStubs = tb.nFiles(allStubPatternarray); + vector> allstub(nAllStubs); + + // output memories + const auto nFullMatches = tb.nFiles(fullMatchPattern); + vector > 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 < nAllProjections; i++) + std::cout << "\t" << tb.fileNames(allProjectionPatternarray).at(i) << "\n"; + for (unsigned i = 0; i < nAllStubs; i++) + std::cout << "\t" << tb.fileNames(allStubPatternarray).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(tprojarray[i], fin_TrackletProjections.at(i), ievt); + auto &fin_AllProjections = tb.files(allProjectionPatternarray); + for (unsigned int i = 0; i < nAllProjections; i++) + writeMemFromFile>(allproj[i], fin_AllProjections.at(i), ievt); + auto &fin_AllStubs = tb.files(allStubPatternarray); + for (unsigned int i = 0; i < nAllStubs; i++) + writeMemFromFile>(allstub[i], fin_AllStubs.at(i), 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(), allstub.data(), allproj.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 > + (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; + +} diff --git a/TrackletAlgorithm/MatchEngineUnit.h b/TrackletAlgorithm/MatchEngineUnit.h index 4abe0b4eac5..41e8a906b31 100644 --- a/TrackletAlgorithm/MatchEngineUnit.h +++ b/TrackletAlgorithm/MatchEngineUnit.h @@ -10,13 +10,11 @@ #include "AllStubMemory.h" #include "AllProjectionMemory.h" #include "FullMatchMemory.h" - -#include - +#include "hls_math.h" #include #include #include -#include "MatchProcessor_parameters.h" +#include "MatchEngineUnit_parameters.h" template static const ap_uint<1 << nbits> hasOneStub() { diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index a187a0e8f91..5204b68ed3e 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -11,7 +11,7 @@ #include "AllStubMemory.h" #include "FullMatchMemory.h" #include "MatchEngineUnit.h" - +#include "hls_math.h" #include #include #include @@ -234,12 +234,12 @@ void readTable_Cuts(ap_uint table[depth]){ if (phi){ // phi cuts if (L==TF::L1){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L1PHIC_phicut.tab" +#include "../emData/MP/tables/MP_L1PHIC_phicut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L2){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L2PHIC_phicut.tab" +#include "../emData/MP/tables/MP_L2PHIC_phicut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L3){ @@ -249,17 +249,17 @@ void readTable_Cuts(ap_uint table[depth]){ } else if (L==TF::L4){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L4PHIC_phicut.tab" +#include "../emData/MP/tables/MP_L4PHIC_phicut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L5){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L5PHIC_phicut.tab" +#include "../emData/MP/tables/MP_L5PHIC_phicut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L6){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L6PHIC_phicut.tab" +#include "../emData/MP/tables/MP_L6PHIC_phicut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else { @@ -269,12 +269,12 @@ void readTable_Cuts(ap_uint table[depth]){ else { // z cuts if (L==TF::L1){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L1PHIC_zcut.tab" +#include "../emData/MP/tables/MP_L1PHIC_zcut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L2){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L2PHIC_zcut.tab" +#include "../emData/MP/tables/MP_L2PHIC_zcut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L3){ @@ -284,17 +284,17 @@ void readTable_Cuts(ap_uint table[depth]){ } else if (L==TF::L4){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L4PHIC_zcut.tab" +#include "../emData/MP/tables/MP_L4PHIC_zcut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L5){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L5PHIC_zcut.tab" +#include "../emData/MP/tables/MP_L5PHIC_zcut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else if (L==TF::L6){ ap_uint tmp[depth] = -#include "../emData/MC/tables/MC_L6PHIC_zcut.tab" +#include "../emData/MP/tables/MP_L6PHIC_zcut.tab" for (int i = 0; i < depth; i++) table[i] = tmp[i]; } else { @@ -313,8 +313,11 @@ void readTable_Cuts(ap_uint table[depth]){ namespace MC { enum imc {UNDEF_ITC, A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, I = 8, J = 9, K = 10, L = 11, M = 12, N = 13, O = 14}; } +template static constexpr bool FMMask(); +template static constexpr uint16_t FMMask(); +#include "MatchProcessor_parameters.h" -template +template void MatchCalculator(BXType bx, ap_uint<1> newtracklet, ap_uint<1>& savedMatch, @@ -412,7 +415,7 @@ void MatchCalculator(BXType bx, ap_int<10> delta_z = stub_z - proj_z_corr; ap_int<14> delta_z_fact = delta_z * kFact; ap_int<18> stub_phi_long = stub_phi; // make longer to allow for shifting - ap_int<18> proj_phi_long = proj_phi_corr; // make longer to allow for shifting + const ap_int<18> &proj_phi_long = proj_phi_corr; // make longer to allow for shifting ap_int<18> shiftstubphi = stub_phi_long << kPhi0_shift; // shift ap_int<18> shiftprojphi = proj_phi_long << (kShift_phi0bit - 1 + kPhi0_shift); // shift ap_int<17> delta_phi = shiftstubphi - shiftprojphi; @@ -456,37 +459,53 @@ void MatchCalculator(BXType bx, if(goodmatch) { // Write out only the best match, based on the seeding switch (proj_seed) { case 0: - fullmatch[0].write_mem(bx,fm,nmcout1-savedMatch); // L1L2 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout1-savedMatch); // L1L2 seed nmcout1+=1-savedMatch; - break; + } + break; case 1: - fullmatch[1].write_mem(bx,fm,nmcout2-savedMatch); // L2L3 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout2-savedMatch); // L2L3 seed nmcout2+=1-savedMatch; - break; + } + break; case 2: - fullmatch[2].write_mem(bx,fm,nmcout3-savedMatch); // L3L4 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout3-savedMatch); // L3L4 seed nmcout3+=1-savedMatch; - break; + } + break; case 3: - fullmatch[3].write_mem(bx,fm,nmcout4-savedMatch); // L5L6 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout4-savedMatch); // L5L6 seed nmcout4+=1-savedMatch; - break; + } + break; case 4: - fullmatch[4].write_mem(bx,fm,nmcout5-savedMatch); // D1D2 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout5-savedMatch); // D1D2 seed nmcout5+=1-savedMatch; - break; + } + break; case 5: - fullmatch[5].write_mem(bx,fm,nmcout6-savedMatch); // D3D4 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout6-savedMatch); // D3D4 seed nmcout6+=1-savedMatch; - break; + } + break; case 6: - fullmatch[6].write_mem(bx,fm,nmcout7-savedMatch); // L1D1 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout7-savedMatch); // L1D1 seed nmcout7+=1-savedMatch; - break; + } + break; case 7: - fullmatch[7].write_mem(bx,fm,nmcout8-savedMatch); // L2D1 seed + if(FMMask()) { + fullmatch[FMCount()].write_mem(bx,fm,nmcout8-savedMatch); // L2D1 seed nmcout8+=1-savedMatch; - break; + } + break; } savedMatch = 1; } @@ -517,7 +536,7 @@ void MatchProcessor(BXType bx, //Initialize table for bend-rinv consistency ap_uint<1> table[kNMatchEngines][(LAYER(table[iMEU]); } @@ -598,7 +617,7 @@ void MatchProcessor(BXType bx, nvmstubs[izbin][3],nvmstubs[izbin][2],nvmstubs[izbin][1],nvmstubs[izbin][0]) = instubdata.getEntries8(bx, izbin); } - PROC_LOOP: for (unsigned int istep = 0; istep < kMaxProc-LoopItersCut; ++istep) { + PROC_LOOP: for (int istep = 0; istep < kMaxProc-LoopItersCut; ++istep) { #pragma HLS PIPELINE II=1 //rewind auto readptr = projbufferarray.getReadPtr(); @@ -619,7 +638,7 @@ void MatchProcessor(BXType bx, bool anyidle = false; - MEU_get_trkids: for(unsigned int iMEU = 0; iMEU < kNMatchEngines; ++iMEU) { + MEU_get_trkids: for(int iMEU = 0; iMEU < kNMatchEngines; ++iMEU) { #pragma HLS unroll matchengine[iMEU].set_empty(); idles[iMEU] = matchengine[iMEU].idle(); @@ -631,9 +650,9 @@ void MatchProcessor(BXType bx, ap_uint smallest = ~emptys; #pragma HLS ARRAY_PARTITION variable=trkids complete dim=0 - MEU_smallest1: for(unsigned int iMEU1 = 0; iMEU1 < kNMatchEngines-1; ++iMEU1) { + MEU_smallest1: for(int iMEU1 = 0; iMEU1 < kNMatchEngines-1; ++iMEU1) { #pragma HLS unroll - MEU_smallest2: for(unsigned int iMEU2 = iMEU1+1; iMEU2 < kNMatchEngines; ++iMEU2) { + MEU_smallest2: for(int iMEU2 = iMEU1+1; iMEU2 < kNMatchEngines; ++iMEU2) { #pragma HLS unroll smallest[iMEU1] = smallest[iMEU1] & (trkids[iMEU1] Date: Tue, 26 Oct 2021 12:08:14 -0400 Subject: [PATCH 03/24] Load all MP instances --- emData/download.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/emData/download.sh b/emData/download.sh index 0d5256b0fc7..56881e494a9 100755 --- a/emData/download.sh +++ b/emData/download.sh @@ -139,7 +139,18 @@ declare -a processing_modules=( "MC_L6PHIC" # MatchProcessor + "MP_L1PHIB" + "MP_L2PHIB" + "MP_L3PHIB" + "MP_L4PHIB" + "MP_L5PHIB" + "MP_L6PHIB" + "MP_L1PHIC" + "MP_L2PHIC" "MP_L3PHIC" + "MP_L4PHIC" + "MP_L5PHIC" + "MP_L6PHIC" # TrackBuilder (aka FitTrack) "FT_L1L2" From 76cae4e74f3b2aac6fc60c5ca45507aee12a79ae Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 26 Oct 2021 13:57:16 -0400 Subject: [PATCH 04/24] Fully working MP --- TestBenches/Macros.h | 50 +++++- TestBenches/MatchProcessorL3_test.cpp | 150 ------------------ TestBenches/MatchProcessor_test.cpp | 37 +++-- .../CombinedConfig/MatchProcessorTopL3.cc | 38 ----- .../CombinedConfig/MatchProcessorTopL3.h | 16 -- TrackletAlgorithm/MatchProcessor.h | 8 +- TrackletAlgorithm/MatchProcessor_parameters.h | 121 +++++++++++++- .../ProjectionRouterBufferArray.h | 2 +- project/script_MP.tcl | 4 +- 9 files changed, 192 insertions(+), 234 deletions(-) delete mode 100644 TestBenches/MatchProcessorL3_test.cpp delete mode 100644 TopFunctions/CombinedConfig/MatchProcessorTopL3.cc delete mode 100644 TopFunctions/CombinedConfig/MatchProcessorTopL3.h diff --git a/TestBenches/Macros.h b/TestBenches/Macros.h index 5a2ac8d7dd5..0c191edd87e 100644 --- a/TestBenches/Macros.h +++ b/TestBenches/Macros.h @@ -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 diff --git a/TestBenches/MatchProcessorL3_test.cpp b/TestBenches/MatchProcessorL3_test.cpp deleted file mode 100644 index 3e139d0a81d..00000000000 --- a/TestBenches/MatchProcessorL3_test.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// ProjectionRouter test bench -#include "MatchProcessorTopL3.h" -#include "CandidateMatchMemory.h" -#include "VMProjectionMemory.h" -#include "ProjectionRouterBuffer.h" -#include "VMStubMEMemoryCM.h" -#include "FileReadUtility.h" -#include "hls_math.h" - -#include -#include -#include -#include -#include - -const int nevents = 100; // number of events to run - -using namespace std; - - - -int main() { - // error counter - int err_count = 0; - - // input memories - static TrackletProjectionMemory tproj[maxTrackletProjections]; - static AllStubMemory allstub; - - VMStubMEMemoryCM inputvmstubs; - - // declare output memory array to be filled by hls simulation - static FullMatchMemory fullmatch[maxFullMatchCopies]; - - ap_uint<8>* valid; - - // open input files - cout << "Open files..." << endl; - - ifstream fin_tproj[maxTrackletProjections]; - ifstream fin_as; - //ifstream fout_ap; - - if (not openDataFile(fin_tproj[0], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2E_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[1], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2F_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[2], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2G_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[3], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2H_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[4], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2I_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[5], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2J_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[6], "MP_L3PHIC/TrackletProjections_TPROJ_L1L2K_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[7], "MP_L3PHIC/TrackletProjections_TPROJ_L5L6B_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[8], "MP_L3PHIC/TrackletProjections_TPROJ_L5L6C_L3PHIC_04.dat")) return -1; - if (not openDataFile(fin_tproj[9], "MP_L3PHIC/TrackletProjections_TPROJ_L5L6D_L3PHIC_04.dat")) return -1; - - ifstream fin_vmstub; - - bool validvmstub = openDataFile(fin_vmstub,"MP_L3PHIC/VMStubs_VMSME_L3PHICn1_04.dat"); - if (not validvmstub) return -1; - - if (not openDataFile(fin_as,"MP_L3PHIC/AllStubs_AS_L3PHICn1_04.dat")) return -1; - - // open file(s) with reference results - ifstream fout_fm1; - ifstream fout_fm2; - ifstream fout_fm3; - ifstream fout_fm4; - ifstream fout_fm5; - ifstream fout_fm6; - ifstream fout_fm7; - - if (not openDataFile(fout_fm1,"MP_L3PHIC/FullMatches_FM_L1L2_L3PHIC_04.dat")) return -1; - if (not openDataFile(fout_fm3,"MP_L3PHIC/FullMatches_FM_L5L6_L3PHIC_04.dat")) return -1; - - // loop over events - for (int ievt = 0; ievt < nevents; ++ievt) { - cout << "Event: " << dec << ievt << endl; - - fullmatch[0].clear(); -// fullmatch[1].clear(); -// fullmatch[2].clear(); - fullmatch[3].clear(); -// fullmatch[4].clear(); -// fullmatch[5].clear(); -// fullmatch[6].clear(); -// fullmatch[7].clear(); - - // read event and write to memories - for(int i = 0; i < maxTrackletProjections; i++) - writeMemFromFile >(tproj[i], fin_tproj[i], ievt); - writeMemFromFile >(allstub, fin_as, ievt); - - writeMemFromFile >(inputvmstubs, fin_vmstub, ievt); - - //set bunch crossing - BXType bx=ievt; - BXType bx_out; - - int noutcandmatch = 0; - - // Unit Under Test - MatchProcessorTopL3(bx, - tproj, - inputvmstubs, - &allstub, - bx_out, - fullmatch); - - // compare the computed outputs with the expected ones for the candidate - // matches - bool truncation = false; - - // compare the computed outputs with the expected ones - std::cout << "FM: L1L2 seeding" << std::endl; - err_count += compareMemWithFile >(fullmatch[0], fout_fm1, ievt, "FullMatch", truncation); - //err_count += compareMemWithFile >(fullmatch[0], fout_fm1, ievt, "FullMatch", truncation); - //std::cout << "FM: L3L4 seeding" << std::endl; - //err_count += compareMemWithFile >(fullmatch2, fout_fm2, ievt, "FullMatch", truncation); - std::cout << "FM: L5L6 seeding" << std::endl; - err_count += compareMemWithFile >(fullmatch[3], fout_fm3, ievt, "FullMatch", truncation); - //err_count += compareMemWithFile >(fullmatch[2], fout_fm3, ievt, "FullMatch", truncation); - //std::cout << "FM: D1D2 seeding" << std::endl; - //err_count += compareMemWithFile >(fullmatch4, fout_fm4, ievt, "FullMatch", truncation); - //std::cout << "FM: D3D4 seeding" << std::endl; - //err_count += compareMemWithFile >(fullmatch5, fout_fm5, ievt, "FullMatch", truncation); - //std::cout << "FM: L1D1 seeding" << std::endl; - //err_count += compareMemWithFile >(fullmatch6, fout_fm6, ievt, "FullMatch", truncation); - //std::cout << "FM: L2D1 seeding" << std::endl; - //err_count += compareMemWithFile >(fullmatch7, fout_fm7, ievt, "FullMatch", truncation); - - - } // end of event loop - - // close files - for(int i = 0; i < maxTrackletProjections; i++) - fin_tproj[i].close(); - fin_vmstub.close(); - - fout_fm1.close(); - fout_fm2.close(); - fout_fm3.close(); - fout_fm4.close(); - fout_fm5.close(); - fout_fm6.close(); - fout_fm7.close(); - - // 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_count > 255) err_count = 255; - return err_count; - -} diff --git a/TestBenches/MatchProcessor_test.cpp b/TestBenches/MatchProcessor_test.cpp index b7c0103c214..3458eea9f2a 100644 --- a/TestBenches/MatchProcessor_test.cpp +++ b/TestBenches/MatchProcessor_test.cpp @@ -27,12 +27,12 @@ int main() { // Define memory patterns const string trackletProjectionPattern = "TrackletProjections*"; - const string allProjectionPatternarray = "AllProj*"; 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 projMemType = (MODULE_ >= MP_L1PHIA_ && MODULE_ <= MP_L3PHID_) ? BARRELPS : (MODULE_ > MP_D5PHID_) ? BARREL2S : DISK; + 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_]); @@ -42,11 +42,11 @@ int main() /////////////////////////// // input memories const auto nTrackletProjections = tb.nFiles(trackletProjectionPattern); - vector tprojarray(nTrackletProjections); - const auto nAllProjections = tb.nFiles(allProjectionPatternarray); - vector> allproj(nAllProjections); - const auto nAllStubs = tb.nFiles(allStubPatternarray); - vector> allstub(nAllStubs); + vector> tprojarray(nTrackletProjections); + const auto nAllStub = tb.nFiles(allStubPatternarray); + vector> allstub(nAllStub); + const auto nVMStubs = tb.nFiles(vmStubPatternarray); + VMStubMEMemoryCM vmstub; // output memories const auto nFullMatches = tb.nFiles(fullMatchPattern); @@ -56,10 +56,10 @@ int main() 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 < nAllProjections; i++) - std::cout << "\t" << tb.fileNames(allProjectionPatternarray).at(i) << "\n"; - for (unsigned i = 0; i < nAllStubs; i++) + 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; @@ -72,13 +72,12 @@ int main() // read event and write to memories auto &fin_TrackletProjections = tb.files(trackletProjectionPattern); for (unsigned int i = 0; i < nTrackletProjections; i++) - writeMemFromFile(tprojarray[i], fin_TrackletProjections.at(i), ievt); - auto &fin_AllProjections = tb.files(allProjectionPatternarray); - for (unsigned int i = 0; i < nAllProjections; i++) - writeMemFromFile>(allproj[i], fin_AllProjections.at(i), ievt); - auto &fin_AllStubs = tb.files(allStubPatternarray); - for (unsigned int i = 0; i < nAllStubs; i++) - writeMemFromFile>(allstub[i], fin_AllStubs.at(i), ievt); + writeMemFromFile>(tprojarray[i], fin_TrackletProjections.at(i), ievt); + auto &fin_AllStub = tb.files(allStubPatternarray); + for (unsigned int i = 0; i < nAllStub; i++) + writeMemFromFile>(allstub[i], fin_AllStub.at(i), ievt); + auto &fin_VMStubs = tb.files(vmStubPatternarray); + writeMemFromFile>(vmstub, fin_VMStubs.at(0), ievt); // clear allarray, output memories before starting for (unsigned int i = 0; i < nFullMatches; i++) @@ -89,7 +88,7 @@ int main() BXType bx_out; // Unit Under Test - TOP_FUNC_(bx, tprojarray.data(), allstub.data(), allproj.data(), bx_out, fullmatcharray.data()); + TOP_FUNC_(bx, tprojarray.data(), vmstub, allstub.data(), bx_out, fullmatcharray.data()); bool truncation = false; auto &fout_fullmatch = tb.files(fullMatchPattern); diff --git a/TopFunctions/CombinedConfig/MatchProcessorTopL3.cc b/TopFunctions/CombinedConfig/MatchProcessorTopL3.cc deleted file mode 100644 index f2b3aa9d4c9..00000000000 --- a/TopFunctions/CombinedConfig/MatchProcessorTopL3.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "MatchProcessorTopL3.h" - -void MatchProcessorTopL3(BXType bx, - const TrackletProjectionMemory projin[maxTrackletProjections], - const VMStubMEMemoryCM& instubdata, - const AllStubMemory* allstub, - BXType& bx_o, - FullMatchMemory fullmatch[maxFullMatchCopies]) { - - #pragma HLS interface register port=bx_o - for(int i = 0; i < maxTrackletProjections; ++i) { - #pragma HLS unroll - #pragma HLS resource variable=projin[i].get_mem() latency=2 - } - #pragma HLS resource variable=instubdata.get_mem() latency=2 - #pragma HLS resource variable=allstub->get_mem() latency=2 - #pragma HLS resource variable=fullmatch[0].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[1].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[2].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[3].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[4].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[5].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[6].get_mem() latency=2 - #pragma HLS resource variable=fullmatch[7].get_mem() latency=2 - - const auto LAYER = TF::L3; - const auto DISK = TF::D1; - const auto PHISEC = MC::C; - MatchProcessor - (bx, - projin, - instubdata, - allstub, - bx_o, - fullmatch); - -} - diff --git a/TopFunctions/CombinedConfig/MatchProcessorTopL3.h b/TopFunctions/CombinedConfig/MatchProcessorTopL3.h deleted file mode 100644 index b08310fdfb2..00000000000 --- a/TopFunctions/CombinedConfig/MatchProcessorTopL3.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MATCHENGINETOPL3_H -#define MATCHENGINETOPL3_H - -#include "MatchProcessor.h" - -constexpr int maxTrackletProjections(10); -constexpr int maxFullMatchCopies(8); - -void MatchProcessorTopL3(BXType bx, - const TrackletProjectionMemory projin[maxTrackletProjections], - const VMStubMEMemoryCM& instubdata, - const AllStubMemory* allstub, - BXType& bx_o, - FullMatchMemory fullmatch[maxFullMatchCopies]); - -#endif diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 5204b68ed3e..cdcd5589145 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -313,8 +313,8 @@ void readTable_Cuts(ap_uint table[depth]){ namespace MC { enum imc {UNDEF_ITC, A = 0, B = 1, C = 2, D = 3, E = 4, F = 5, G = 6, H = 7, I = 8, J = 9, K = 10, L = 11, M = 12, N = 13, O = 14}; } -template static constexpr bool FMMask(); -template static constexpr uint16_t FMMask(); +template constexpr bool FMMask(); +template constexpr uint32_t FMMask(); #include "MatchProcessor_parameters.h" template @@ -766,10 +766,10 @@ void MatchProcessor(BXType bx, //memory the projection points to // number of bits used to distinguish the different modules in each layer/disk - auto nbits_all = LAYER!=0 ? nbitsallstubs[LAYER-1] : nbitsallstubs[N_LAYER + DISK-1]; + auto nbits_all = LAYER!=0 ? nbitsallstubs[LAYER-1] : nbitsallstubs[trklet::N_LAYER + DISK-1]; // number of bits used to distinguish between VMs within a module - auto nbits_vmme = LAYER!=0 ? nbits_vmmeall[LAYER-1] : nbits_vmmeall[N_LAYER + DISK-1]; + auto nbits_vmme = LAYER!=0 ? nbits_vmmeall[LAYER-1] : nbits_vmmeall[trklet::N_LAYER + DISK-1]; // bits used for routing iphi = iphiproj.range(iphiproj.length()-nbits_all-1,iphiproj.length()-nbits_all-nbits_vmme); diff --git a/TrackletAlgorithm/MatchProcessor_parameters.h b/TrackletAlgorithm/MatchProcessor_parameters.h index b828588fce8..c970dd3e513 100644 --- a/TrackletAlgorithm/MatchProcessor_parameters.h +++ b/TrackletAlgorithm/MatchProcessor_parameters.h @@ -1,16 +1,81 @@ -#ifndef TrackAlgorithm_MatchProcessor_parameters_h -#define TrackAlgorithm_MatchProcessor_parameters_h +#ifndef TrackletAlgorithm_MatchProcessor_parameters_h +#define TrackletAlgorithm_MatchProcessor_parameters_h // This file contains numbers of memories and bit masks that are specific to // each MatchProcessor and that come directly from the wiring. // -// The validity of each of the barrel CM memories is determined by +// The validity of each of the barrel Tracklet Parameter memories is determined by // FMMask. The bits of this mask, from least significant to most // significant, represent the memories in the order they are passed to // MatchProcessor; e.g., the LSB corresponds to // TF::L1L2. If a bit is set, the corresponding memory is // valid, if it is not, the corresponding memory is not valid. +// magic numbers for MP_L1PHIA +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIB +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIC +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHID +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIE +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIF +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIG +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L1PHIH +template<> constexpr uint32_t FMMask() { + return 0xBE; +} + +// magic numbers for MP_L2PHIA +template<> constexpr uint32_t FMMask() { + return 0x1C; +} + +// magic numbers for MP_L2PHIB +template<> constexpr uint32_t FMMask() { + return 0x1C; +} + +// magic numbers for MP_L2PHIC +template<> constexpr uint32_t FMMask() { + return 0x1C; +} + +// magic numbers for MP_L2PHID +template<> constexpr uint32_t FMMask() { + return 0x1C; +} + +// magic numbers for MP_L3PHIA +template<> constexpr uint32_t FMMask() { + return 0x9; +} + // magic numbers for MP_L3PHIB template<> constexpr uint32_t FMMask() { return 0x9; @@ -21,21 +86,71 @@ template<> constexpr uint32_t FMMask() { return 0x9; } +// magic numbers for MP_L3PHID +template<> constexpr uint32_t FMMask() { + return 0x9; +} + +// magic numbers for MP_L4PHIA +template<> constexpr uint32_t FMMask() { + return 0xB; +} + // magic numbers for MP_L4PHIB template<> constexpr uint32_t FMMask() { return 0xB; } +// magic numbers for MP_L4PHIC +template<> constexpr uint32_t FMMask() { + return 0xB; +} + +// magic numbers for MP_L4PHID +template<> constexpr uint32_t FMMask() { + return 0xB; +} + +// magic numbers for MP_L5PHIA +template<> constexpr uint32_t FMMask() { + return 0x7; +} + // magic numbers for MP_L5PHIB template<> constexpr uint32_t FMMask() { return 0x7; } +// magic numbers for MP_L5PHIC +template<> constexpr uint32_t FMMask() { + return 0x7; +} + +// magic numbers for MP_L5PHID +template<> constexpr uint32_t FMMask() { + return 0x7; +} + +// magic numbers for MP_L6PHIA +template<> constexpr uint32_t FMMask() { + return 0x5; +} + // magic numbers for MP_L6PHIB template<> constexpr uint32_t FMMask() { return 0x5; } +// magic numbers for MP_L6PHIC +template<> constexpr uint32_t FMMask() { + return 0x5; +} + +// magic numbers for MP_L6PHID +template<> constexpr uint32_t FMMask() { + return 0x5; +} + // return mask bit AND mask template constexpr bool FMMask() { return FMMask() & (1< class ProjectionRouterBufferArray { public: diff --git a/project/script_MP.tcl b/project/script_MP.tcl index ca830f5480d..2be8b328e27 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -1,6 +1,6 @@ # Script to generate project for MP # vivado_hls -f script_MP.tcl -# vivado_hls -p match_calc +# vivado_hls -p match_processor # WARNING: this will wipe out the original project by the same name # get some information about the executable and environment @@ -14,7 +14,7 @@ set modules_to_test { set module_to_export MP_L3PHIC # create new project (deleting any existing one of same name) -open_project -reset match_calc +open_project -reset match_processor # source files set CFLAGS {-std=c++11 -I../TrackletAlgorithm} From 9baf91ed60b3e1ef34575315e6d33c24ec708383 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 26 Oct 2021 14:35:20 -0400 Subject: [PATCH 05/24] Small fixes to match MC --- TrackletAlgorithm/MatchProcessor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index cdcd5589145..e1ead0fd534 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -229,7 +229,7 @@ ap_uint iabs( ap_int value ) // Template to get look up tables // Table for phi or z cuts -template +template void readTable_Cuts(ap_uint table[depth]){ if (phi){ // phi cuts if (L==TF::L1){ @@ -357,9 +357,9 @@ void MatchCalculator(BXType bx, const auto kFact = (LAYER < TF::L4)? 1 : (1<<(kNbitszprojL123-kNbitszprojL456)); // fact_ in emulation defined in MC const auto kPhi0_shift = (LAYER < TF::L4)? 3 : 0; // phi0shift_ in emulation defined in MC - constexpr int kShift_phi0bit = 1; // phi0bitshift in emulation defined in constants + const auto kShift_phi0bit = 1; // phi0bitshift in emulation defined in constants const ap_uint<10> kPhi_corr_shift_L123 = 7 + kNbitsdrinv + kShift_phi0bit - kShift_Rinv - kShift_Phider; // icorrshift for L123 - const ap_uint<10> kPhi_corr_shift_L456 = kPhi_corr_shift_L123 - 10 - kNbitsrL456; // icorrshift for L456 + const ap_uint<10> kPhi_corr_shift_L456 = kPhi_corr_shift_L123 - 10 + kNbitsrL456; // icorrshift for L456 const auto kPhi_corr_shift = (LAYER < TF::L4)? kPhi_corr_shift_L123 : kPhi_corr_shift_L456; // icorrshift_ in emulation const ap_uint<10> kZ_corr_shiftL123 = (-1-kShift_PS_zderL); // icorzshift for L123 (6 in L3) const ap_uint<10> kZ_corr_shiftL456 = (-1-kShift_2S_zderL + kNbitszprojL123 - kNbitszprojL456 + kNbitsrL456 - kNbitsrL123); // icorzshift for L456 From 5c41e42359cfe60388ea09e2eb952a64373145dd Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 26 Oct 2021 14:38:45 -0400 Subject: [PATCH 06/24] Fixed issue with L3PHIB --- TrackletAlgorithm/MatchProcessor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index e1ead0fd534..85e85d32e98 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -433,7 +433,7 @@ void MatchCalculator(BXType bx, // Full match typename AllProjection::AProjTCSEED projseed_next; - FullMatch fm(fm_tcid,fm_tkid,(ap_uint<3>(2),fm_asid),fm_stubr,fm_phi,fm_z); + FullMatch fm(fm_tcid,fm_tkid,fm_asphi,fm_asid,fm_stubr,fm_phi,fm_z); //----------------------------------------------------------------------------------------------------------- //-------------------------------------- BEST MATCH LOGIC BLOCK --------------------------------------------- From ca17b597f1d2ec03d76799fe5396f81239bba6d8 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 10:15:43 -0400 Subject: [PATCH 07/24] Fixed MP script for TopFunctions --- .gitlab-ci.yml | 2 +- .../MatchEngineUnit_parameters.h | 118 ++++++++++++++++++ project/script_MP.tcl | 2 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 TrackletAlgorithm/MatchEngineUnit_parameters.h diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f517e7c5ba2..c87646ef495 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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/MatchProcessorTop.cpp' TB-quality-check: <<: *template_quality-check variables: diff --git a/TrackletAlgorithm/MatchEngineUnit_parameters.h b/TrackletAlgorithm/MatchEngineUnit_parameters.h new file mode 100644 index 00000000000..b80f798565c --- /dev/null +++ b/TrackletAlgorithm/MatchEngineUnit_parameters.h @@ -0,0 +1,118 @@ +#ifndef TrackAlgorithm_MatchEngineUnit_parameters_h +#define TrackAlgorithm_MatchEngineUnit_parameters_h + +// This file contains numbers of memories and bit masks that are specific to +// each MEU and that come directly from the wiring. +// + +template +static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFullUnit() { + ap_uint<(1 << (2 * kNBitsBuffer))> lut; + for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { +#pragma HLS unroll + ap_uint wptr, rptr; + ap_uint<2 * kNBitsBuffer> address(i); + (rptr,wptr) = address; + auto wptr1 = wptr+1; + auto wptr2 = wptr+2; + bool result = wptr1==rptr || wptr2==rptr; + lut[i] = result; + } + return lut; +} + +template +static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFull3Unit() { + ap_uint<(1 << (2 * kNBitsBuffer))> lut; + for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { +#pragma HLS unroll + ap_uint wptr, rptr; + ap_uint<2 * kNBitsBuffer> address(i); + (rptr,wptr) = address; + ap_uint wptr1 = wptr+1; + ap_uint wptr2 = wptr+2; + ap_uint wptr3 = wptr+3; + bool result = wptr1==rptr || wptr2==rptr || wptr3==rptr; + lut[i] = result; + } + return lut; +} + +template +static const ap_uint<(1 << (2 * kNBitsBuffer))> emptyUnit() { + ap_uint<(1 << (2 * kNBitsBuffer))> lut; + for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { +#pragma HLS unroll + ap_uint wptr, rptr; + ap_uint<2 * kNBitsBuffer> address(i); + (rptr,wptr) = address; + bool result = wptr==rptr; + lut[i] = result; + } + return lut; +} + +template +static const ap_uint<(1 << (2 * kNBitsBuffer))> geq() { + ap_uint<(1 << (2 * kNBitsBuffer))> lut; + for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) { +#pragma HLS unroll + ap_uint istub, nstubs; + ap_uint<2 * kNBitsBuffer> address(i); + (nstubs,istub) = address; + bool result = istub+1>=nstubs; + lut[i] = result; + } + return lut; +} + +template +static const ap_uint<(1 << kNBitsBuffer)> nextUnit() { + ap_uint<(1 << kNBitsBuffer)> lut; + for(int i = 0; i < (1 << kNBitsBuffer); ++i) { +#pragma HLS unroll + ap_uint ptr(i); + lut[i] = ptr+1; + } + return lut; +} + +template +static const ap_uint<1 << nbits> isLessThanSize() { + ap_uint<1 << nbits> tab(0); + ap_uint Max(max); + ap_uint Min(-max); + for(int i = 0; i < 1<= Min) tab[i] = 1; + } + else { + if(i < Max || i > Min) tab[i] = 1; + } + } + return tab; +} + +template +static const ap_uint<1 << 2*nbits> isLessThanSize() { + ap_uint<1 << 2*nbits> tab(0); + ap_uint Max(max); + ap_uint Min(-max); + for(int i = 0; i < 1<<2*nbits; ++i) { +#pragma HLS unroll + ap_uint projphi; + ap_uint stubphi; + ap_uint address(i); + (projphi,stubphi) = address; + ap_uint result = projphi - stubphi; + if(lessThan) { + if(result <= Max || result >= Min) tab[i] = 1; + } + else { + if(result < Max || result > Min) tab[i] = 1; + } + } + return tab; +} +#endif diff --git a/project/script_MP.tcl b/project/script_MP.tcl index 2be8b328e27..ea0a82ee553 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -18,7 +18,7 @@ open_project -reset match_processor # source files set CFLAGS {-std=c++11 -I../TrackletAlgorithm} -add_files ../TrackletAlgorithm/MatchProcessorTop.cc -cflags "$CFLAGS" +add_files ../TopFunctions/MatchProcessorTop.cc -cflags "$CFLAGS" add_files -tb ../TestBenches/MatchProcessor_test.cpp -cflags "$CFLAGS" # data files From bf49a218aeb0d3e3cc637c9cabd49b754640e834 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 10:36:20 -0400 Subject: [PATCH 08/24] Added generate_MP.py --- emData/generate_MP.py | 288 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100755 emData/generate_MP.py diff --git a/emData/generate_MP.py b/emData/generate_MP.py new file mode 100755 index 00000000000..5889f50017a --- /dev/null +++ b/emData/generate_MP.py @@ -0,0 +1,288 @@ +#!/usr/bin/env python + +# This script generates MatchProcessor_parameters.h, +# MatchProcessorTop.h, and MatchProcessorTop.cc in the +# TrackletAlgorithm/ directory. Currently supports all MPs for L3_PHIC. + +from __future__ import absolute_import +from __future__ import print_function +import os +import re +import sys +import argparse + +TF_index = ['L1L2', 'L2L3', 'L3L4', 'L5L6', 'D1D2', 'D3D4', 'L1D1', 'L2D1'] +TF_index = {k:v for v,k in enumerate(TF_index)} + +def ASRegion(region): + if region in ['L1', 'L2', 'L3']: + return 'BARRELPS' + elif region in ['L4', 'L5', 'L6']: + return 'BARREL2S' + else: + return 'DISK' + +def APRegion(region): + if region in ['L1', 'L2', 'L3']: + return 'BARRELPS' + elif region in ['L4', 'L5', 'L6']: + return 'BARREL2S' + else: + return 'DISK' + + +def VMStubMERegion(region): + if region in ['L1', 'L2', 'L3']: + return 'BARRELPS' + elif region in ['L4', 'L5', 'L6']: + return 'BARREL2S' + else: + return 'DISK' + +def getTProjAndVMRegions(module): + if any(psword in module for psword in ["L1","L2","L3"]): TProjRegion = "BARRELPS" + elif any(psword in module for psword in ["L4","L5","L6"]): TProjRegion = "BARREL2S" + else: TProjRegion = "DISK" + + if any(psword in module for psword in ["L1","L2","L3","L4","L5","L6"]): VMProjRegion = "BARREL" + else: VMProjRegion = "DISK" + + if any(psword in module for psword in ["L1","L2","L3"]): VMStubRegion = "BARRELPS" + elif any(psword in module for psword in ["L4","L5","L6"]): VMStubRegion = "BARREL2S" + else: VMStubRegion = "DISK" + + return TProjRegion, VMProjRegion, VMStubRegion + +def FMRegion(region): + if region in ['L1', 'L2', 'L3', 'L4', 'L5', 'L6']: + return 'BARREL' + else: + return 'DISK' + +parser = argparse.ArgumentParser(description="This script generates MatchCalculatorTop.h, MatchCalculatorTop.cc, and\ +MatchCalculator_parameters.h in the TopFunctions/ directory.", + epilog="") +parser.add_argument("-o", "--outputDirectory", metavar="DIR", default="../TopFunctions/", type=str, help="The directory in which to write the output files (default=%(default)s)") +parser.add_argument("-w", "--wiresFileName", metavar="WIRES_FILE", default="LUTs/wires.dat", type=str, help="Name and directory of the configuration file for wiring (default = %(default)s)") +arguments = parser.parse_args() + +# First, parse the wires file and store the memory names associated with MPs in +# dictionaries with the MP names as keys. +with open(arguments.wiresFileName) as wiresFile: + TPMems = {} + FMMems = {} + for line in wiresFile: + # Only barrel-only seeds are supported right now. + if "MP_D" in line: + continue # No disks for now + line = line.rstrip() + mpName = re.sub(r".*MP_(......).*", r"MP_\1", line) + memName = line.split()[0] + if memName.startswith("TPROJ_"): + if mpName not in TPMems: + TPMems[mpName] = [] + TPMems[mpName].append(memName) + if memName.startswith("FM_"): + FM = re.sub(r"FM_(....)_......", r"\1", memName) + if mpName not in FMMems: + FMMems[mpName] = [] + FMMems[mpName].append(FM) + +# Open and print out preambles for the parameters and top files. +dirname = os.path.dirname(os.path.realpath('__file__')) +with open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessor_parameters.h"), "w") as parametersFile, \ + open(os.path.join(dirname, arguments.outputDirectory, "MatchEngineUint_parameters.h"), "w") as meuParametersFile, \ + open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessorTop.h"), "w") as topHeaderFile, \ + open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessorTop.cc"), "w") as topFile: + meuParametersFile.write( + "#ifndef TrackAlgorithm_MatchEngineUnit_parameters_h\n" + "#define TrackAlgorithm_MatchEngineUnit_parameters_h\n" + "\n" + "// This file contains numbers of memories and bit masks that are specific to\n" + "// each MEU and that come directly from the wiring.\n" + "//\n" + "\n" + "template\n" + "static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFullUnit() {\n" + " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" + " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" + "#pragma HLS unroll\n" + " ap_uint wptr, rptr;\n" + " ap_uint<2 * kNBitsBuffer> address(i);\n" + " (rptr,wptr) = address;\n" + " auto wptr1 = wptr+1;\n" + " auto wptr2 = wptr+2;\n" + " bool result = wptr1==rptr || wptr2==rptr;\n" + " lut[i] = result;\n" + " }\n" + " return lut;\n" + "}\n" + "\n" + "template\n" + "static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFull3Unit() {\n" + " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" + " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" + "#pragma HLS unroll\n" + " ap_uint wptr, rptr;\n" + " ap_uint<2 * kNBitsBuffer> address(i);\n" + " (rptr,wptr) = address;\n" + " ap_uint wptr1 = wptr+1;\n" + " ap_uint wptr2 = wptr+2;\n" + " ap_uint wptr3 = wptr+3;\n" + " bool result = wptr1==rptr || wptr2==rptr || wptr3==rptr;\n" + " lut[i] = result;\n" + " }\n" + " return lut;\n" + "}\n" + "\n" + "template\n" + "static const ap_uint<(1 << (2 * kNBitsBuffer))> emptyUnit() {\n" + " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" + " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" + "#pragma HLS unroll\n" + " ap_uint wptr, rptr;\n" + " ap_uint<2 * kNBitsBuffer> address(i);\n" + " (rptr,wptr) = address;\n" + " bool result = wptr==rptr;\n" + " lut[i] = result;\n" + ) + + parametersFile.write( + "#ifndef TrackletAlgorithm_MatchProcessor_parameters_h\n" + "#define TrackletAlgorithm_MatchProcessor_parameters_h\n" + "\n" + "// This file contains numbers of memories and bit masks that are specific to\n" + "// each MatchProcessor and that come directly from the wiring.\n" + "//\n" + "// The validity of each of the barrel Tracklet Parameter memories is determined by\n" + "// FMMask. The bits of this mask, from least significant to most\n" + "// significant, represent the memories in the order they are passed to\n" + "// MatchProcessor; e.g., the LSB corresponds to\n" + "// TF::L1L2. If a bit is set, the corresponding memory is\n" + "// valid, if it is not, the corresponding memory is not valid.\n" + ) + topHeaderFile.write( + "#ifndef TrackletAlgorithm_MatchProcessorTop_h\n" + "#define TrackletAlgorithm_MatchProcessorTop_h\n" + "\n" + "#include \"MatchProcessor.h\"\n" + "\n" + ) + topFile.write( + "#include \"MatchProcessorTop.h\"\n" + "\n" + "////////////////////////////////////////////////////////////////////////////////\n" + "// Top functions for various MatchProcessors (MP). For each iteration of\n" + "// the main processing loop, a MP retrieves an array of Traklet Projections,\n" + "// and computes Full Matches from each.\n" + "////////////////////////////////////////////////////////////////////////////////\n" + ) + + # Calculate parameters and print out parameters and top function for each MP. + for mpName in sorted(TPMems.keys()): + seed = re.sub(r"MP_(..)....", r"\1", mpName) + iMP = re.sub(r"MP_.....(.)", r"\1", mpName) + + # numbers of memories + nTPMem = len(TPMems[mpName]) + nFMMem = len(FMMems[mpName]) + FMMask = 0 + for FM in FMMems[mpName]: + FMMask = FMMask | (1 << TF_index[FM]) + + # Print out parameters for this MP. + parametersFile.write( + "\n" + "// magic numbers for " + mpName + "\n" + "template<> constexpr uint32_t FMMask() {\n" + " return 0x%X;\n" + "}\n" % FMMask + ) + + TProjRegion, VMProjRegion, VMStubRegion = getTProjAndVMRegions(seed) + # Print out prototype for top function for this MP. + topHeaderFile.write( + "\n" + "constexpr int " + seed + "PHI" + iMP + "maxTrackletProjections(" + str(nTPMem) + ");\n" + "constexpr int " + seed + "PHI" + iMP + "maxFullMatchCopies(" + str(nFMMem) + ");\n" + "\n" + "void MatchProcessor_" + seed + "PHI" + iMP + "(\n" + " const BXType bx,\n" + " const TrackletProjectionMemory<" + TProjRegion + "> projin[" + seed + "PHI" + iMP + "maxTrackletProjections],\n" + " const VMStubMEMemoryCM<" + VMStubMERegion(seed) + ", 3, 3, kNMatchEngines>& instubdata,\n" + " const AllStubMemory<" + ASRegion(seed) + ">* allstub,\n" + " BXType& bx_o,\n" + " FullMatchMemory<" + FMRegion(seed) + "> fullmatch[" + seed + "PHI" + iMP + "maxFullMatchCopies]\n" + ");\n" + ) + + # Print out definition of top function for this MP. + topFile.write( + "\n" + "void MatchProcessor_" + seed + "PHI" + iMP + "(\n" + " const BXType bx,\n" + " const TrackletProjectionMemory<" + TProjRegion + "> projin[" + seed + "PHI" + iMP + "maxTrackletProjections],\n" + " const VMStubMEMemoryCM<" + VMStubMERegion(seed) + ", 3, 3, kNMatchEngines>& instubdata,\n" + " const AllStubMemory<" + ASRegion(seed) + ">* allstub,\n" + " BXType& bx_o,\n" + " FullMatchMemory<" + FMRegion(seed) + "> fullmatch[" + seed + "PHI" + iMP + "maxFullMatchCopies]\n" + ") {\n" + "#pragma HLS inline off\n" + "#pragma HLS interface register port=bx_o\n" + ) + if nTPMem == 1: + topFile.write("#pragma HLS resource variable=match.get_mem() latency=2\n") + else: + for i in range(nTPMem): + topFile.write("#pragma HLS resource variable=match[" + str(i) + "].get_mem() latency=2\n") + if nFMMem == 1: + topFile.write("#pragma HLS resource variable=fullmatch.get_mem() latency=2\n") + else: + for i in range(nFMMem): + topFile.write("#pragma HLS resource variable=fullmatch[" + str(i) + "].get_mem() latency=2\n") + topFile.write( + "#pragma HLS resource variable=allstub->get_mem() latency=2\n" + "#pragma HLS resource variable=instubdata.get_mem() latency=2\n" + "\n" + "MP_" + seed + "PHI" + iMP + ": MatchProcessor<" + "" + TProjRegion + ", " + VMStubRegion + ", " + VMProjRegion + ", " + ASRegion(seed) + ", " + APRegion(seed) + ", " + FMRegion(seed) + ", " + seed + "PHI" + iMP + "maxTrackletProjections" + ", " + seed + "PHI" + iMP + "maxFullMatchCopies" + ",\n" + " TF::" + seed + ", " + "TF::" + "D1" + ", " + "MC::" + iMP + "> (\n" + " bx,\n" + " projin,\n" + " instubdata,\n" + " allstub,\n" + " bx_o,\n" + " fullmatch\n" + " );\n" + "}\n" + ) + + # Print out endifs and close files. + parametersFile.write( + "\n" + "// return mask bit AND mask\n" + "template constexpr bool FMMask() {\n" + " return FMMask() & (1<\n" + "static const ap_uint<1 << Seed> FMCount() {\n" + " ap_uint<1< bits(-1);\n" + " ap_uint<1< mask = bits & FMMask();\n" + " int slot = 0;\n" + " for(int i = 0; i < Seed; ++i) {\n" + " slot += mask.range(i,i);\n" + " }\n" + " return slot;\n" + "}\n\n" + "#endif\n" + ) + topHeaderFile.write( + "\n" + "#endif\n" + ) + topFile.write( + "\n" + "////////////////////////////////////////////////////////////////////////////////\n" + ) From 8d3e1f2e8c4f0fa1c99f259c9d9f6f14805d3ae2 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 10:55:35 -0400 Subject: [PATCH 09/24] MP top cpp -> cc --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c87646ef495..66b4cb70f92 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -181,7 +181,7 @@ MP-quality-check: <<: *template_quality-check variables: VIVADO_VERSION: "2019.2" - CLANG_TIDY_FILES: '../TestBenches/MatchProcessor_test.cpp ../TopFunctions/MatchProcessorTop.cpp' + CLANG_TIDY_FILES: '../TestBenches/MatchProcessor_test.cpp ../TopFunctions/MatchProcessorTop.cc' TB-quality-check: <<: *template_quality-check variables: From 787caddcffad9d936b9d7476859933c3d28b8f45 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 11:43:01 -0400 Subject: [PATCH 10/24] Run generate_MP.py in download.sh --- emData/download.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/emData/download.sh b/emData/download.sh index 56881e494a9..2f9438ec99f 100755 --- a/emData/download.sh +++ b/emData/download.sh @@ -274,6 +274,7 @@ mkdir -p ../TopFunctions/ReducedConfig mkdir -p ../TopFunctions/CombinedConfig ./generate_VMRCM.py -d -w LUTsCM/wires.dat -o ../TopFunctions/CombinedConfig ./generate_TP.py -w LUTsCM/wires.dat -o ../TopFunctions/CombinedConfig +./generate_MP.py -w LUTsCM/wires.dat -o ../TopFunctions/CombinedConfig # Exit now if we are only downloading and unpacking LUTs.tar.gz. if [[ $tables_only != 0 ]] From 334a3fd74609f849549cee5e26e5e404aab8576d Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 12:17:36 -0400 Subject: [PATCH 11/24] MP top in CombinedConfig --- .gitlab-ci.yml | 2 +- project/script_MP.tcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 66b4cb70f92..5fe0f3950c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -181,7 +181,7 @@ MP-quality-check: <<: *template_quality-check variables: VIVADO_VERSION: "2019.2" - CLANG_TIDY_FILES: '../TestBenches/MatchProcessor_test.cpp ../TopFunctions/MatchProcessorTop.cc' + CLANG_TIDY_FILES: '../TestBenches/MatchProcessor_test.cpp ../TopFunctions/CombinedConfig/MatchProcessorTop.cc' TB-quality-check: <<: *template_quality-check variables: diff --git a/project/script_MP.tcl b/project/script_MP.tcl index ea0a82ee553..2af7635a468 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -18,7 +18,7 @@ open_project -reset match_processor # source files set CFLAGS {-std=c++11 -I../TrackletAlgorithm} -add_files ../TopFunctions/MatchProcessorTop.cc -cflags "$CFLAGS" +add_files ../TopFunctions/CombinedConfig/MatchProcessorTop.cc -cflags "$CFLAGS" add_files -tb ../TestBenches/MatchProcessor_test.cpp -cflags "$CFLAGS" # data files From 78740e2a234e7bd63c62de01a904f15b99afa2eb Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Thu, 28 Oct 2021 12:44:10 -0400 Subject: [PATCH 12/24] Fixed gcc paths --- project/script_MP.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/script_MP.tcl b/project/script_MP.tcl index 2af7635a468..1b0b329f1e2 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -17,7 +17,7 @@ set module_to_export MP_L3PHIC open_project -reset match_processor # source files -set CFLAGS {-std=c++11 -I../TrackletAlgorithm} +set CFLAGS {-std=c++11 -I../TrackletAlgorithm -I../TopFunctions/CombinedConfig} add_files ../TopFunctions/CombinedConfig/MatchProcessorTop.cc -cflags "$CFLAGS" add_files -tb ../TestBenches/MatchProcessor_test.cpp -cflags "$CFLAGS" From ece25623202fdf1cb78a6cc0c6972458f2634c12 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 2 Nov 2021 11:47:21 -0400 Subject: [PATCH 13/24] Added MP to Constants.h --- TrackletAlgorithm/Constants.h | 5 +++-- TrackletAlgorithm/MatchProcessor.h | 7 +------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/TrackletAlgorithm/Constants.h b/TrackletAlgorithm/Constants.h index 408486d8626..c34aff8fa4e 100644 --- a/TrackletAlgorithm/Constants.h +++ b/TrackletAlgorithm/Constants.h @@ -30,7 +30,7 @@ constexpr unsigned int kNbitsrfinebintable = 4; // List of module types namespace module { - enum type {UNKNOWN, IR, VMR, TE, TC, PR, ME, MC, NMODULES}; + enum type {UNKNOWN, IR, VMR, TE, TC, PR, ME, MC, MP, NMODULES}; }; // Map from a module type to an offset used to reduce the number of iterations @@ -44,7 +44,8 @@ constexpr unsigned kMaxProcOffset(const module::type m) { (m == module::PR ? 0 : (m == module::ME ? 0 : (m == module::MC ? 0 : - (0))))))); + (m == module::MP ? 0 : + (0)))))))); } // Memory diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 85e85d32e98..9d73a9dd03d 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -105,11 +105,6 @@ namespace PR constexpr unsigned int zbins_adjust_PSseed = 1; constexpr unsigned int zbins_adjust_2Sseed = 4; - // Number of loop iterations subtracted from the full 108 so that the function - // stays synchronized with other functions in the chain. Once we get these - // functions to rewind correctly, this can be set to zero (or simply removed) - constexpr unsigned int LoopItersCut = 0; - inline void zbinLUTinit(ap_uint<2*MEBinsBits> zbinLUT[128], int zbins_adjust_PSseed, int zbins_adjust_2Sseed){ for(unsigned int ibin=0; ibin<128; ibin++) { @@ -617,7 +612,7 @@ void MatchProcessor(BXType bx, nvmstubs[izbin][3],nvmstubs[izbin][2],nvmstubs[izbin][1],nvmstubs[izbin][0]) = instubdata.getEntries8(bx, izbin); } - PROC_LOOP: for (int istep = 0; istep < kMaxProc-LoopItersCut; ++istep) { + PROC_LOOP: for (ap_uint istep = 0; istep < kMaxProc - kMaxProcOffset(module::MP); istep++) { #pragma HLS PIPELINE II=1 //rewind auto readptr = projbufferarray.getReadPtr(); From 6c2bac1af61f08dedf33f84bfecee0e5e4194536 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 2 Nov 2021 12:14:06 -0400 Subject: [PATCH 14/24] Improved L1 (tested PHIB and PHIC) --- TrackletAlgorithm/MatchProcessor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 9d73a9dd03d..a6d218001de 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -761,10 +761,10 @@ void MatchProcessor(BXType bx, //memory the projection points to // number of bits used to distinguish the different modules in each layer/disk - auto nbits_all = LAYER!=0 ? nbitsallstubs[LAYER-1] : nbitsallstubs[trklet::N_LAYER + DISK-1]; + auto nbits_all = LAYER < trklet::N_LAYER ? nbitsallstubs[LAYER] : nbitsallstubs[trklet::N_LAYER + DISK]; // number of bits used to distinguish between VMs within a module - auto nbits_vmme = LAYER!=0 ? nbits_vmmeall[LAYER-1] : nbits_vmmeall[trklet::N_LAYER + DISK-1]; + auto nbits_vmme = LAYER < trklet::N_LAYER ? nbits_vmmeall[LAYER] : nbits_vmmeall[trklet::N_LAYER + DISK]; // bits used for routing iphi = iphiproj.range(iphiproj.length()-nbits_all-1,iphiproj.length()-nbits_all-nbits_vmme); From c74ebb78a6f6cba20c21d8fb99e85035cff88248 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Mon, 15 Nov 2021 09:48:26 -0500 Subject: [PATCH 15/24] Uncommented tables --- TrackletAlgorithm/MatchProcessor.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index a6d218001de..8b840cdf580 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -151,7 +151,6 @@ void readTable(ap_uint<1> table[]){ } } -/* FIXME uncomment these out when testing L2,L5, and L6. Need to be added to download.sh to work. if (L==TF::L2) { bool tmp[256]= #include "../emData/ME/tables/METable_L2.tab" @@ -160,7 +159,6 @@ void readTable(ap_uint<1> table[]){ table[i]=tmp[i]; } } -*/ if (L==TF::L3) { bool tmp[256]= @@ -180,7 +178,6 @@ void readTable(ap_uint<1> table[]){ } } -/* if (L==TF::L5) { bool tmp[512]= #include "../emData/ME/tables/METable_L5.tab" @@ -198,7 +195,6 @@ void readTable(ap_uint<1> table[]){ table[i]=tmp[i]; } } -*/ From bba2722b7d4525fc7c5ebed7bc758264b1528756 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Mon, 6 Dec 2021 12:47:03 -0500 Subject: [PATCH 16/24] Fixed synthesis issues --- TrackletAlgorithm/MatchProcessor.h | 1 + emData/generate_MP.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 8b840cdf580..6df0d2e5d25 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -582,6 +582,7 @@ void MatchProcessor(BXType bx, MatchEngineUnit matchengine[kNMatchEngines]; #pragma HLS ARRAY_PARTITION variable=matchengine complete dim=0 #pragma HLS ARRAY_PARTITION variable=instubdata complete dim=1 +#pragma HLS ARRAY_PARTITION variable=projin dim=1 #pragma HLS ARRAY_PARTITION variable=numbersin complete dim=0 #pragma HLS dependence variable=istub inter false diff --git a/emData/generate_MP.py b/emData/generate_MP.py index 5889f50017a..8313477bbf8 100755 --- a/emData/generate_MP.py +++ b/emData/generate_MP.py @@ -231,10 +231,10 @@ def FMRegion(region): "#pragma HLS interface register port=bx_o\n" ) if nTPMem == 1: - topFile.write("#pragma HLS resource variable=match.get_mem() latency=2\n") + topFile.write("#pragma HLS resource variable=projin.get_mem() latency=2\n") else: for i in range(nTPMem): - topFile.write("#pragma HLS resource variable=match[" + str(i) + "].get_mem() latency=2\n") + topFile.write("#pragma HLS resource variable=projin[" + str(i) + "].get_mem() latency=2\n") if nFMMem == 1: topFile.write("#pragma HLS resource variable=fullmatch.get_mem() latency=2\n") else: From 1bd5260a39efde8c7862082a46cd8fae95bda808 Mon Sep 17 00:00:00 2001 From: carriganm95 Date: Mon, 6 Dec 2021 12:53:26 -0500 Subject: [PATCH 17/24] Changes to work with future SW emulation (#217) --- TrackletAlgorithm/MatchEngine.h | 3 --- TrackletAlgorithm/MatchEngineUnit.h | 2 +- TrackletAlgorithm/MatchProcessor.h | 1 - emData/generate_MP.py | 16 +++++++++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/TrackletAlgorithm/MatchEngine.h b/TrackletAlgorithm/MatchEngine.h index eeda7eea18c..d0b2f2377b4 100644 --- a/TrackletAlgorithm/MatchEngine.h +++ b/TrackletAlgorithm/MatchEngine.h @@ -16,9 +16,6 @@ #endif #endif -// HLS Headers -#include "hls_math.h" - // STL Headers #include #include diff --git a/TrackletAlgorithm/MatchEngineUnit.h b/TrackletAlgorithm/MatchEngineUnit.h index 41e8a906b31..29a4a82c71a 100644 --- a/TrackletAlgorithm/MatchEngineUnit.h +++ b/TrackletAlgorithm/MatchEngineUnit.h @@ -10,7 +10,7 @@ #include "AllStubMemory.h" #include "AllProjectionMemory.h" #include "FullMatchMemory.h" -#include "hls_math.h" +#include #include #include #include diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 6df0d2e5d25..3f9caa24cdf 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -11,7 +11,6 @@ #include "AllStubMemory.h" #include "FullMatchMemory.h" #include "MatchEngineUnit.h" -#include "hls_math.h" #include #include #include diff --git a/emData/generate_MP.py b/emData/generate_MP.py index 8313477bbf8..389a00972b7 100755 --- a/emData/generate_MP.py +++ b/emData/generate_MP.py @@ -14,6 +14,9 @@ TF_index = ['L1L2', 'L2L3', 'L3L4', 'L5L6', 'D1D2', 'D3D4', 'L1D1', 'L2D1'] TF_index = {k:v for v,k in enumerate(TF_index)} +maxTPMems = "constexpr int maxTPMemories[" +maxFMMems = "constexpr int maxFMMemories[" + def ASRegion(region): if region in ['L1', 'L2', 'L3']: return 'BARRELPS' @@ -178,6 +181,9 @@ def FMRegion(region): "////////////////////////////////////////////////////////////////////////////////\n" ) + maxTPMems += str(len(TPMems.keys())) + "] = {" + maxFMMems += str(len(TPMems.keys())) + "] = {" + # Calculate parameters and print out parameters and top function for each MP. for mpName in sorted(TPMems.keys()): seed = re.sub(r"MP_(..)....", r"\1", mpName) @@ -189,6 +195,12 @@ def FMRegion(region): FMMask = 0 for FM in FMMems[mpName]: FMMask = FMMask | (1 << TF_index[FM]) + + maxTPMems += seed + "PHI" + iMP + "maxTrackletProjections" + maxFMMems += seed + "PHI" + iMP + "maxFullMatchCopies" + if mpName != sorted(TPMems.keys())[-1]: + maxTPMems += ",\n " + maxFMMems += ",\n " # Print out parameters for this MP. parametersFile.write( @@ -279,8 +291,10 @@ def FMRegion(region): "#endif\n" ) topHeaderFile.write( + "\n" + maxTPMems + "};\n" + "\n" + maxFMMems + "};\n" "\n" - "#endif\n" + "\n#endif\n" ) topFile.write( "\n" From 731e5ecb6f172d610697a1698ec2e9bf6adff11b Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Mon, 6 Dec 2021 15:49:16 -0500 Subject: [PATCH 18/24] Removed assert --- TrackletAlgorithm/MatchEngineUnit.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/TrackletAlgorithm/MatchEngineUnit.h b/TrackletAlgorithm/MatchEngineUnit.h index 29a4a82c71a..a5787aefe1d 100644 --- a/TrackletAlgorithm/MatchEngineUnit.h +++ b/TrackletAlgorithm/MatchEngineUnit.h @@ -10,7 +10,6 @@ #include "AllStubMemory.h" #include "AllProjectionMemory.h" #include "FullMatchMemory.h" -#include #include #include #include @@ -103,7 +102,6 @@ class MatchEngineUnit : public MatchEngineUnitBase { second_ = isSecond[index]; phiPlus_ = isPhiPlus[index]; nstubs_ = nstubsall_[index]; - assert(nstubs_!=0); ivmphi = projbuffer.getPhi(); iphi_ = iphi; auto const qdata=projbuffer_; @@ -154,14 +152,12 @@ inline typename ProjectionRouterBuffer::TCID getTCID( AllProjection allproj(allprojdata); return allproj.getTCID(); } - assert(!idle_||good_||good__); if (good__) { return projbuffer___.getTCID(); } if (good_) { return projbuffer__.getTCID(); } - assert(tcid==projbuffer_.getTCID()); return tcid; } @@ -281,7 +277,6 @@ inline MATCH read() { second_ = index[0]; phiPlus_ = index[1]; nstubs_ = nstubsall_[index]; - assert(nstubs_!=0); } } else { istub_++; From 06149aba7ec7112d5e0bade089fc4e33b8b66b44 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 7 Dec 2021 08:37:01 -0500 Subject: [PATCH 19/24] Removed MEU params from generate_MP.py --- emData/generate_MP.py | 53 ------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/emData/generate_MP.py b/emData/generate_MP.py index 389a00972b7..fd0408a9f9b 100755 --- a/emData/generate_MP.py +++ b/emData/generate_MP.py @@ -94,61 +94,8 @@ def FMRegion(region): # Open and print out preambles for the parameters and top files. dirname = os.path.dirname(os.path.realpath('__file__')) with open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessor_parameters.h"), "w") as parametersFile, \ - open(os.path.join(dirname, arguments.outputDirectory, "MatchEngineUint_parameters.h"), "w") as meuParametersFile, \ open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessorTop.h"), "w") as topHeaderFile, \ open(os.path.join(dirname, arguments.outputDirectory, "MatchProcessorTop.cc"), "w") as topFile: - meuParametersFile.write( - "#ifndef TrackAlgorithm_MatchEngineUnit_parameters_h\n" - "#define TrackAlgorithm_MatchEngineUnit_parameters_h\n" - "\n" - "// This file contains numbers of memories and bit masks that are specific to\n" - "// each MEU and that come directly from the wiring.\n" - "//\n" - "\n" - "template\n" - "static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFullUnit() {\n" - " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" - " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" - "#pragma HLS unroll\n" - " ap_uint wptr, rptr;\n" - " ap_uint<2 * kNBitsBuffer> address(i);\n" - " (rptr,wptr) = address;\n" - " auto wptr1 = wptr+1;\n" - " auto wptr2 = wptr+2;\n" - " bool result = wptr1==rptr || wptr2==rptr;\n" - " lut[i] = result;\n" - " }\n" - " return lut;\n" - "}\n" - "\n" - "template\n" - "static const ap_uint<(1 << (2 * kNBitsBuffer))> nearFull3Unit() {\n" - " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" - " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" - "#pragma HLS unroll\n" - " ap_uint wptr, rptr;\n" - " ap_uint<2 * kNBitsBuffer> address(i);\n" - " (rptr,wptr) = address;\n" - " ap_uint wptr1 = wptr+1;\n" - " ap_uint wptr2 = wptr+2;\n" - " ap_uint wptr3 = wptr+3;\n" - " bool result = wptr1==rptr || wptr2==rptr || wptr3==rptr;\n" - " lut[i] = result;\n" - " }\n" - " return lut;\n" - "}\n" - "\n" - "template\n" - "static const ap_uint<(1 << (2 * kNBitsBuffer))> emptyUnit() {\n" - " ap_uint<(1 << (2 * kNBitsBuffer))> lut;\n" - " for(int i = 0; i < (1 << (2 * kNBitsBuffer)); ++i) {\n" - "#pragma HLS unroll\n" - " ap_uint wptr, rptr;\n" - " ap_uint<2 * kNBitsBuffer> address(i);\n" - " (rptr,wptr) = address;\n" - " bool result = wptr==rptr;\n" - " lut[i] = result;\n" - ) parametersFile.write( "#ifndef TrackletAlgorithm_MatchProcessor_parameters_h\n" From ed14b18a49696c90d143ad49ac21fac48894b123 Mon Sep 17 00:00:00 2001 From: carriganm95 Date: Fri, 17 Dec 2021 13:53:25 -0500 Subject: [PATCH 20/24] Delete MatchProcessor_parameters.h --- TrackletAlgorithm/MatchProcessor_parameters.h | 170 ------------------ 1 file changed, 170 deletions(-) delete mode 100644 TrackletAlgorithm/MatchProcessor_parameters.h diff --git a/TrackletAlgorithm/MatchProcessor_parameters.h b/TrackletAlgorithm/MatchProcessor_parameters.h deleted file mode 100644 index c970dd3e513..00000000000 --- a/TrackletAlgorithm/MatchProcessor_parameters.h +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef TrackletAlgorithm_MatchProcessor_parameters_h -#define TrackletAlgorithm_MatchProcessor_parameters_h - -// This file contains numbers of memories and bit masks that are specific to -// each MatchProcessor and that come directly from the wiring. -// -// The validity of each of the barrel Tracklet Parameter memories is determined by -// FMMask. The bits of this mask, from least significant to most -// significant, represent the memories in the order they are passed to -// MatchProcessor; e.g., the LSB corresponds to -// TF::L1L2. If a bit is set, the corresponding memory is -// valid, if it is not, the corresponding memory is not valid. - -// magic numbers for MP_L1PHIA -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIB -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIC -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHID -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIE -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIF -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIG -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L1PHIH -template<> constexpr uint32_t FMMask() { - return 0xBE; -} - -// magic numbers for MP_L2PHIA -template<> constexpr uint32_t FMMask() { - return 0x1C; -} - -// magic numbers for MP_L2PHIB -template<> constexpr uint32_t FMMask() { - return 0x1C; -} - -// magic numbers for MP_L2PHIC -template<> constexpr uint32_t FMMask() { - return 0x1C; -} - -// magic numbers for MP_L2PHID -template<> constexpr uint32_t FMMask() { - return 0x1C; -} - -// magic numbers for MP_L3PHIA -template<> constexpr uint32_t FMMask() { - return 0x9; -} - -// magic numbers for MP_L3PHIB -template<> constexpr uint32_t FMMask() { - return 0x9; -} - -// magic numbers for MP_L3PHIC -template<> constexpr uint32_t FMMask() { - return 0x9; -} - -// magic numbers for MP_L3PHID -template<> constexpr uint32_t FMMask() { - return 0x9; -} - -// magic numbers for MP_L4PHIA -template<> constexpr uint32_t FMMask() { - return 0xB; -} - -// magic numbers for MP_L4PHIB -template<> constexpr uint32_t FMMask() { - return 0xB; -} - -// magic numbers for MP_L4PHIC -template<> constexpr uint32_t FMMask() { - return 0xB; -} - -// magic numbers for MP_L4PHID -template<> constexpr uint32_t FMMask() { - return 0xB; -} - -// magic numbers for MP_L5PHIA -template<> constexpr uint32_t FMMask() { - return 0x7; -} - -// magic numbers for MP_L5PHIB -template<> constexpr uint32_t FMMask() { - return 0x7; -} - -// magic numbers for MP_L5PHIC -template<> constexpr uint32_t FMMask() { - return 0x7; -} - -// magic numbers for MP_L5PHID -template<> constexpr uint32_t FMMask() { - return 0x7; -} - -// magic numbers for MP_L6PHIA -template<> constexpr uint32_t FMMask() { - return 0x5; -} - -// magic numbers for MP_L6PHIB -template<> constexpr uint32_t FMMask() { - return 0x5; -} - -// magic numbers for MP_L6PHIC -template<> constexpr uint32_t FMMask() { - return 0x5; -} - -// magic numbers for MP_L6PHID -template<> constexpr uint32_t FMMask() { - return 0x5; -} - -// return mask bit AND mask -template constexpr bool FMMask() { - return FMMask() & (1< -static const ap_uint<1 << Seed> FMCount() { - ap_uint<1< bits(-1); - ap_uint<1< mask = bits & FMMask(); - int slot = 0; - for(int i = 0; i < Seed; ++i) { - slot += mask.range(i,i); - } - return slot; -} - -#endif From a92a1b3aed338b71c9cee54c35400c08554f0543 Mon Sep 17 00:00:00 2001 From: Anders Ryd Date: Sat, 18 Dec 2021 11:56:55 -0500 Subject: [PATCH 21/24] Fixes to MatchProcessor - now full agreement in L1-L6 --- TrackletAlgorithm/MatchEngineUnit.h | 8 +++++--- TrackletAlgorithm/MatchProcessor.h | 21 +++++++++++++++------ emData/download.sh | 18 ++++++++++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/TrackletAlgorithm/MatchEngineUnit.h b/TrackletAlgorithm/MatchEngineUnit.h index a5787aefe1d..c19a0475f02 100644 --- a/TrackletAlgorithm/MatchEngineUnit.h +++ b/TrackletAlgorithm/MatchEngineUnit.h @@ -47,6 +47,7 @@ class MatchEngineUnit : public MatchEngineUnitBase { stubmask_ = 0; nstubs_ = 0; idle_ = true; + empty_ = true; good_ = false; good__ = false; } @@ -88,6 +89,7 @@ class MatchEngineUnit : public MatchEngineUnitBase { idle_ = false; bx = bxin; istub_ = 0; + unit_ = unit; AllProjection aProj(projbuffer.getAllProj()); projbuffer_ = projbuffer; projindex = projbuffer.getIndex(); @@ -215,11 +217,10 @@ inline MATCH read() { good_ = idle_ ? false : good_; good_ = nearfull ? false : good_; + + bool process = (!idle_) && (!nearfull); - // vmproj index - //typename VMProjection::VMPZBIN projzbin; - // Buffer still has projections to read out //If the buffer is not empty we have a projection that we need to //process. @@ -310,6 +311,7 @@ inline MATCH read() { ap_int<2> shift_; bool idle_; int ivmphi; + int unit_; // only used for debugging to identify MEU ap_uint<3> iphi_; BXType bx; bool empty_; diff --git a/TrackletAlgorithm/MatchProcessor.h b/TrackletAlgorithm/MatchProcessor.h index 3f9caa24cdf..6ff47c89851 100644 --- a/TrackletAlgorithm/MatchProcessor.h +++ b/TrackletAlgorithm/MatchProcessor.h @@ -445,7 +445,7 @@ void MatchCalculator(BXType bx, // Store bestmatch goodmatch = true; } - + if(goodmatch) { // Write out only the best match, based on the seeding switch (proj_seed) { case 0: @@ -637,7 +637,16 @@ void MatchProcessor(BXType bx, emptys[iMEU] = matchengine[iMEU].empty(); trkids[iMEU] = matchengine[iMEU].getTrkID(); } - + + //This printout exactly matches printout in emulation for tracking code differences + /* + std::cout << "istep = " << istep << " projBuff: " << readptr << " " << writeptr << " " << projBuffNearFull; + for(int iMEU = 0; iMEU < kNMatchEngines; ++iMEU) { + std::cout << " MEU"< smallest = ~emptys; #pragma HLS ARRAY_PARTITION variable=trkids complete dim=0 @@ -769,10 +778,10 @@ void MatchProcessor(BXType bx, iphiproj.length()-nbits_all-nbits_vmme-3); int nextrabits = 2; - int overlapbits = nbits_vmme + nextrabits; + int overlapbits = nbits_vmme + nbits_all + nextrabits; unsigned int extrabits = iphiproj.range(iphiproj.length() - overlapbits-1, iphiproj.length() - overlapbits - nextrabits); - + unsigned int ivmPlus = iphi; ap_int<2> shift = 0; @@ -803,14 +812,14 @@ void MatchProcessor(BXType bx, nstublastMinus = 0; nstublastPlus = 0; } - + ap_uint<16> nstubs=(nstublastPlus, nstubfirstPlus, nstublastMinus, nstubfirstMinus); VMProjection vmproj(index, zbin, finez, finephi, rinv, psseed); AllProjection allproj(projdata_.getTCID(), projdata_.getTrackletIndex(), projdata_.getPhi(), projdata_.getRZ(), projdata_.getPhiDer(), projdata_.getRZDer()); - if (nstubs!=0) { + if (nstubs!=0) { ProjectionRouterBuffer projbuffertmp(allproj.raw(), ivmMinus, shift, trackletid, nstubs, zfirst, vmproj, psseed); projbufferarray.addProjection(projbuffertmp); } diff --git a/emData/download.sh b/emData/download.sh index 2f9438ec99f..7265a194643 100755 --- a/emData/download.sh +++ b/emData/download.sh @@ -9,13 +9,23 @@ set -e memprints_url_reduced="https://cernbox.cern.ch/index.php/s/LkVZR8WRYGPJcPe/download" luts_url_reduced="https://cernbox.cern.ch/index.php/s/2zppC0iJ3eEy5C9/download" +#### test 211005/211217 #### +# Standard configuration +memprints_url="https://aryd.web.cern.ch/aryd/MemPrints_Standard_211005.tgz" +luts_url="https://aryd.web.cern.ch/aryd/LUTs_Standard_211005.tgz" +# Combined modules +memprints_url_cm="https://aryd.web.cern.ch/aryd/MemPrints_Combined_211217.tgz" +luts_url_cm="https://aryd.web.cern.ch/aryd/LUTs_Combined_211217.tgz" + + + #### fw_synch_210611 #### # Standard configuration -memprints_url="https://cernbox.cern.ch/index.php/s/hUJUsqvCnKv2YdQ/download" -luts_url="https://cernbox.cern.ch/index.php/s/9Yms3LCKJsg7UmF/download" +#memprints_url="https://cernbox.cern.ch/index.php/s/hUJUsqvCnKv2YdQ/download" +#luts_url="https://cernbox.cern.ch/index.php/s/9Yms3LCKJsg7UmF/download" # Combined modules -memprints_url_cm="https://cernbox.cern.ch/index.php/s/RFpmFiSnFC84x0O/download" -luts_url_cm="https://cernbox.cern.ch/index.php/s/kqZu8R7Ftu0YPoO/download" +#memprints_url_cm="https://cernbox.cern.ch/index.php/s/RFpmFiSnFC84x0O/download" +#luts_url_cm="https://cernbox.cern.ch/index.php/s/kqZu8R7Ftu0YPoO/download" #### fw_synch_210503 #### # Standard configuration From bd72f8787be43ac579e62b54b58d38a207cae6cf Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Mon, 20 Dec 2021 10:23:54 -0500 Subject: [PATCH 22/24] Updated scripts, CI should no longer fail --- .gitlab-ci.yml | 1 - project/script_MP.tcl | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5fe0f3950c0..8aab0a3b45b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -263,7 +263,6 @@ MC-vivado-hls-build: MP-vivado-hls-build: <<: *template_hls-build needs: ["download", "MP-quality-check"] - allow_failure: true # FIXME: remove after all errors are fixed variables: EXECUTABLE: 'vivado_hls' VIVADO_VERSION: "2019.2" diff --git a/project/script_MP.tcl b/project/script_MP.tcl index 1b0b329f1e2..c1dbb15c5d2 100644 --- a/project/script_MP.tcl +++ b/project/script_MP.tcl @@ -7,7 +7,12 @@ source env_hls.tcl set modules_to_test { + {MP_L1PHIC} + {MP_L2PHIC} {MP_L3PHIC} + {MP_L4PHIC} + {MP_L5PHIC} + {MP_L6PHIC} } # module_to_export must correspond to the default macros set at the top of the # test bench; otherwise, the C/RTL cosimulation will fail From 2dab0c3f0782d615bc23f2d9007cf52ffcbe6f35 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 18 Jan 2022 09:34:27 -0500 Subject: [PATCH 23/24] Commented out custom TVs, allow MP CI to fail again --- .gitlab-ci.yml | 1 + emData/download.sh | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8aab0a3b45b..60f77c875d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -262,6 +262,7 @@ MC-vivado-hls-build: PROJ_NAME: "MC" MP-vivado-hls-build: <<: *template_hls-build + allow_failure: true needs: ["download", "MP-quality-check"] variables: EXECUTABLE: 'vivado_hls' diff --git a/emData/download.sh b/emData/download.sh index 7265a194643..2df7fcf7e15 100755 --- a/emData/download.sh +++ b/emData/download.sh @@ -11,11 +11,11 @@ luts_url_reduced="https://cernbox.cern.ch/index.php/s/2zppC0iJ3eEy5C9/download" #### test 211005/211217 #### # Standard configuration -memprints_url="https://aryd.web.cern.ch/aryd/MemPrints_Standard_211005.tgz" -luts_url="https://aryd.web.cern.ch/aryd/LUTs_Standard_211005.tgz" +#memprints_url="https://aryd.web.cern.ch/aryd/MemPrints_Standard_211005.tgz" +#luts_url="https://aryd.web.cern.ch/aryd/LUTs_Standard_211005.tgz" # Combined modules -memprints_url_cm="https://aryd.web.cern.ch/aryd/MemPrints_Combined_211217.tgz" -luts_url_cm="https://aryd.web.cern.ch/aryd/LUTs_Combined_211217.tgz" +#memprints_url_cm="https://aryd.web.cern.ch/aryd/MemPrints_Combined_211217.tgz" +#luts_url_cm="https://aryd.web.cern.ch/aryd/LUTs_Combined_211217.tgz" From c13b4b9481d29912178cd2494e2ef121b6086b18 Mon Sep 17 00:00:00 2001 From: Brent Yates Date: Tue, 18 Jan 2022 09:59:40 -0500 Subject: [PATCH 24/24] Fixed download.sh issue --- emData/download.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/emData/download.sh b/emData/download.sh index 2df7fcf7e15..0fbacaa484d 100755 --- a/emData/download.sh +++ b/emData/download.sh @@ -21,11 +21,11 @@ luts_url_reduced="https://cernbox.cern.ch/index.php/s/2zppC0iJ3eEy5C9/download" #### fw_synch_210611 #### # Standard configuration -#memprints_url="https://cernbox.cern.ch/index.php/s/hUJUsqvCnKv2YdQ/download" -#luts_url="https://cernbox.cern.ch/index.php/s/9Yms3LCKJsg7UmF/download" +memprints_url="https://cernbox.cern.ch/index.php/s/hUJUsqvCnKv2YdQ/download" +luts_url="https://cernbox.cern.ch/index.php/s/9Yms3LCKJsg7UmF/download" # Combined modules -#memprints_url_cm="https://cernbox.cern.ch/index.php/s/RFpmFiSnFC84x0O/download" -#luts_url_cm="https://cernbox.cern.ch/index.php/s/kqZu8R7Ftu0YPoO/download" +memprints_url_cm="https://cernbox.cern.ch/index.php/s/RFpmFiSnFC84x0O/download" +luts_url_cm="https://cernbox.cern.ch/index.php/s/kqZu8R7Ftu0YPoO/download" #### fw_synch_210503 #### # Standard configuration