Skip to content

Commit 5f3bd55

Browse files
authored
Attempt to fix Future L1 Track SW + bugs in HLS memory classes. (#347)
* Fix compile errors for templated functions * Fixed clashes with Future SW code * fix to earlier commit * Modify write_mem so it can handle old txt files that dont have page number * Fix bug that only one quarter of memory being checked * Fix writing outside array bug * tweak * Optimised CPU use * fix compilation issue * tweak * Fix bug in this PR * Fixed bug in PR * Fixed bug in PR * Fix bug in PR * Switch to MemPrintSplit input files for Future SW * Changed TP tp used LutsSplit with CombinedCM chain * Give variable better name * Give variable better name * Replace tabs by spaces
1 parent d704970 commit 5f3bd55

10 files changed

+176
-195
lines changed

TestBenches/FileReadUtility.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ unsigned int compareMemWithMemPage(const MemType& memory_ref, const MemType& mem
256256
constexpr int lsb = (LSB >= 0 && MSB >= LSB) ? LSB : 0;
257257
constexpr int msb = (LSB >= 0 && MSB >= LSB) ? MSB : MemType::getWidth() - 1;
258258

259-
for (unsigned int ipage = 0; ipage < 4; ++ipage) {
259+
for (unsigned int ipage = 0; ipage < memory_ref.getNPage(); ++ipage) {
260260
//FIXME
261-
for (unsigned int i = 0; i < memory_ref.getDepth()/4; ++i) {
261+
for (unsigned int i = 0; i < memory_ref.getDepth(); ++i) {
262262
const auto data_ref_raw = memory_ref.read_mem(ievt,i,ipage).raw();
263263
const auto data_com_raw = memory.read_mem(ievt,i,ipage).raw();
264264
const auto data_ref = data_ref_raw.range(msb,lsb);

TrackletAlgorithm/MatchProcessor.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ template<TF::layerDisk Layer, TF::phiRegion PHI> constexpr uint32_t NPageSum();
901901

902902
#include "MatchProcessor_parameters.h"
903903

904-
template<regionType ASTYPE, regionType APTYPE, regionType VMSMEType, regionType FMTYPE, int maxFullMatchCopies, TF::layerDisk LAYER=TF::L1, TF::phiRegion PHISEC=TF::A>
904+
template<regionType ASTYPE, regionType APTYPE, regionType VMSMEType, regionType FMTYPE, int maxFullMatchVariants, TF::layerDisk LAYER=TF::L1, TF::phiRegion PHISEC=TF::A>
905905
void MatchCalculator(BXType bx,
906906
ap_uint<1> newtracklet,
907907
ap_uint<1>& isMatch,
@@ -913,7 +913,7 @@ void MatchCalculator(BXType bx,
913913
const AllStubMemory<ASTYPE>* allstub,
914914
const AllProjection<APTYPE>& proj,
915915
ap_uint<VMStubMECMBase<VMSMEType>::kVMSMEIDSize> stubid,
916-
FullMatchMemory<FMTYPE> fullmatch[maxFullMatchCopies]
916+
FullMatchMemory<FMTYPE> fullmatch[maxFullMatchVariants]
917917
){
918918

919919
#pragma HLS inline
@@ -1180,7 +1180,7 @@ constexpr unsigned kNbitsrzbinMPDisk = kNbitsrzbin + 1;
11801180

11811181
//////////////////////////////
11821182
// MatchProcessor
1183-
template<regionType PROJTYPE, regionType VMSMEType, unsigned kNbitsrzbinMP, regionType VMPTYPE, regionType ASTYPE, regionType FMTYPE, unsigned int nINMEM, int maxFullMatchCopies,
1183+
template<regionType PROJTYPE, regionType VMSMEType, unsigned kNbitsrzbinMP, regionType VMPTYPE, regionType ASTYPE, regionType FMTYPE, unsigned int nINMEM, int maxFullMatchVariants,
11841184
TF::layerDisk LAYER=TF::L1, TF::phiRegion PHISEC=TF::A>
11851185
void MatchProcessor(BXType bx,
11861186
// because Vivado HLS cannot synthesize an array of
@@ -1190,7 +1190,7 @@ void MatchProcessor(BXType bx,
11901190
const VMStubMEMemoryCM<VMSMEType, kNbitsrzbinMP, kNbitsphibin, kNMatchEngines>& instubdata,
11911191
const AllStubMemory<ASTYPE>* allstub,
11921192
BXType& bx_o,
1193-
FullMatchMemory<FMTYPE> fullmatch[maxFullMatchCopies]
1193+
FullMatchMemory<FMTYPE> fullmatch[maxFullMatchVariants]
11941194
){
11951195
#pragma HLS inline
11961196

@@ -1458,7 +1458,7 @@ void MatchProcessor(BXType bx,
14581458

14591459
if (hasMatch_save) {
14601460
isMatch = newtracklet_save ? ap_uint<1>(0) : isMatch;
1461-
MatchCalculator<ASTYPE, APTYPE, VMSMEType, FMTYPE, maxFullMatchCopies, LAYER, PHISEC>
1461+
MatchCalculator<ASTYPE, APTYPE, VMSMEType, FMTYPE, maxFullMatchVariants, LAYER, PHISEC>
14621462
(bx, newtracklet_save, isMatch, savedMatch, best_delta_z, best_delta_phi, best_delta_rphi, best_delta_r, allstub, allproj_save, stubindex_save,
14631463
fullmatch);
14641464
}
@@ -1483,7 +1483,6 @@ void MatchProcessor(BXType bx,
14831483
newtracklet_save = newtracklet;
14841484
allproj_save = allproj;
14851485
stubindex_save = stubindex;
1486-
14871486
} //end MC if
14881487

14891488

TrackletAlgorithm/MemoryTemplate.h

+48-49
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,41 @@ template<class DataType, unsigned int NBIT_BX, unsigned int NBIT_ADDR>
3131
// (1<<NBIT_ADDR): depth of the memory for each BX
3232
class MemoryTemplate
3333
{
34+
private:
3435
#ifdef CMSSW_GIT_HASH
3536
static constexpr unsigned int NBIT_BX = 0;
3637
#endif
37-
38+
3839
public:
40+
static constexpr unsigned int DEPTH_BX = 1<<NBIT_BX;
41+
static constexpr unsigned int DEPTH_ADDR = 1<<NBIT_ADDR;
42+
3943
typedef typename DataType::BitWidths BitWidths;
4044
typedef ap_uint<NBIT_BX> BunchXingT;
4145
typedef ap_uint<NBIT_ADDR> NEntryT;
4246

4347
protected:
4448

45-
DataType dataarray_[1<<NBIT_BX][1<<NBIT_ADDR]; // data array
46-
NEntryT nentries_[1<<NBIT_BX]; // number of entries
49+
DataType dataarray_[DEPTH_BX][DEPTH_ADDR]; // data array
50+
NEntryT nentries_[DEPTH_BX]; // number of entries
4751

4852
public:
4953

50-
unsigned int getDepth() const {return (1<<NBIT_ADDR);}
51-
unsigned int getNBX() const {return (1<<NBIT_BX);}
54+
unsigned int getDepth() const {return DEPTH_ADDR;}
55+
unsigned int getNBX() const {return DEPTH_BX;}
5256

5357
NEntryT getEntries(BunchXingT bx) const {
5458
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
55-
return nentries_[bx];
59+
return nentries_[bx];
5660
}
5761

58-
const DataType (&get_mem() const)[1<<NBIT_BX][1<<NBIT_ADDR] {return dataarray_;}
62+
const DataType (&get_mem() const)[DEPTH_BX][DEPTH_ADDR] {return dataarray_;}
5963

6064
DataType read_mem(BunchXingT ibx, ap_uint<NBIT_ADDR> index) const
6165
{
62-
// TODO: check if valid
63-
if(!NBIT_BX) ibx = 0;
64-
return dataarray_[ibx][index];
66+
// TODO: check if valid
67+
if(!NBIT_BX) ibx = 0;
68+
return dataarray_[ibx][index];
6569
}
6670

6771
template<class SpecType>
@@ -72,7 +76,7 @@ class MemoryTemplate
7276
#ifdef __SYNTHESIS__
7377
0;
7478
#else
75-
nentries_[ibx];
79+
nentries_[ibx];
7680
#endif
7781
return write_mem(ibx,data,addr_index);
7882
}
@@ -83,10 +87,10 @@ class MemoryTemplate
8387
#pragma HLS inline
8488
if(!NBIT_BX) ibx = 0;
8589
static_assert(
86-
std::is_same<DataType, SpecType>::value
87-
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
88-
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
89-
, "Invalid conversion between data types");
90+
std::is_same<DataType, SpecType>::value
91+
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
92+
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
93+
, "Invalid conversion between data types");
9094
DataType sameData(data.raw());
9195
return write_mem(ibx,sameData,addr_index);
9296
}
@@ -98,7 +102,7 @@ class MemoryTemplate
98102
#ifdef __SYNTHESIS__
99103
0;
100104
#else
101-
nentries_[ibx];
105+
nentries_[ibx];
102106
#endif
103107
return write_mem(ibx,data,addr_index);
104108
}
@@ -108,7 +112,7 @@ class MemoryTemplate
108112
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
109113
#pragma HLS inline
110114
if(!NBIT_BX) ibx = 0;
111-
if (addr_index < (1<<NBIT_ADDR)) {
115+
if (addr_index < DEPTH_ADDR) {
112116
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
113117
//The vhd memory implementation will write to the correct address!!
114118
dataarray_[ibx][0] = data;
@@ -126,28 +130,23 @@ class MemoryTemplate
126130
}
127131
}
128132

129-
bool write_mem_new(BunchXingT ibx, DataType data, NEntryT addr_index)
133+
bool write_mem_new(BunchXingT ibx, DataType data, ap_uint<1> overwrite)
130134
{
131135
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
132136
#pragma HLS inline
133137
if(!NBIT_BX) ibx = 0;
134-
if (addr_index < (1<<NBIT_ADDR)) {
135-
//dataarray_[ibx][addr_index] = data;
138+
if (nentries_[ibx] < DEPTH_ADDR) {
136139
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
137140
//The vhd memory implementation will write to the correct address!!
138141
dataarray_[ibx][0] = data;
139142
#else
140-
if(addr_index == 0) {
141-
dataarray_[ibx][nentries_[ibx]++] = data;
143+
if(overwrite == 0) {
144+
dataarray_[ibx][nentries_[ibx]++] = data;
142145
} else {
143-
dataarray_[ibx][nentries_[ibx]-1] = data;
146+
dataarray_[ibx][nentries_[ibx]-1] = data;
144147
}
145148
#endif
146149

147-
#ifdef CMSSW_GIT_HASH
148-
nentries_[ibx] = addr_index + 1;
149-
#endif
150-
151150
return true;
152151
} else {
153152
return false;
@@ -158,17 +157,17 @@ class MemoryTemplate
158157
#ifndef __SYNTHESIS__
159158
MemoryTemplate()
160159
{
161-
clear();
160+
clear();
162161
}
163162

164163
~MemoryTemplate(){}
165164

166165
void clear()
167166
{
168167
DataType data("0",16);
169-
MEM_RST: for (size_t ibx=0; ibx<(1<<NBIT_BX); ++ibx) {
168+
MEM_RST: for (size_t ibx=0; ibx<DEPTH_BX; ++ibx) {
170169
nentries_[ibx] = 0;
171-
for (size_t addr=0; addr<(1<<NBIT_ADDR); ++addr) {
170+
for (size_t addr=0; addr<DEPTH_ADDR; ++addr) {
172171
write_mem(ibx,data,addr);
173172
}
174173
}
@@ -177,47 +176,47 @@ class MemoryTemplate
177176
// write memory from text file
178177
bool write_mem(BunchXingT ibx, const char* datastr, int base=16)
179178
{
180-
if(!NBIT_BX) ibx = 0;
181-
DataType data(datastr, base);
182-
NEntryT nent = nentries_[ibx];
183-
bool success = write_mem(ibx, data, nent);
179+
if(!NBIT_BX) ibx = 0;
180+
DataType data(datastr, base);
181+
NEntryT nent = nentries_[ibx];
182+
bool success = write_mem(ibx, data, nent);
184183

185-
return success;
184+
return success;
186185
}
187186

188-
bool write_mem(BunchXingT ibx, const std::string datastr, int base=16)
187+
bool write_mem(BunchXingT ibx, const std::string& datastr, int base=16)
189188
{
190-
return write_mem(ibx, datastr.c_str(), base);
189+
return write_mem(ibx, datastr.c_str(), base);
191190
}
192191

193192
// print memory contents
194193
void print_data(const DataType data) const
195194
{
196195
edm::LogVerbatim("L1trackHLS") << std::hex << data.raw() << std::endl;
197-
// TODO: overload '<<' in data class
196+
// TODO: overload '<<' in data class
198197
}
199198

200199
void print_entry(BunchXingT bx, NEntryT index) const
201200
{
202-
print_data(dataarray_[bx][index]);
201+
print_data(dataarray_[bx][index]);
203202
}
204203

205204
void print_mem(BunchXingT bx) const
206205
{
207-
for (unsigned int i = 0; i < nentries_[bx]; ++i) {
208-
edm::LogVerbatim("L1trackHLS") << bx << " " << i << " ";
209-
print_entry(bx,i);
210-
}
206+
for (unsigned int i = 0; i < nentries_[bx]; ++i) {
207+
edm::LogVerbatim("L1trackHLS") << bx << " " << i << " ";
208+
print_entry(bx,i);
209+
}
211210
}
212211

213212
void print_mem() const
214213
{
215-
for (unsigned int ibx = 0; ibx < (1<<NBIT_BX); ++ibx) {
216-
for (unsigned int i = 0; i < nentries_[ibx]; ++i) {
217-
edm::LogVerbatim("L1trackHLS") << ibx << " " << i << " ";
218-
print_entry(ibx,i);
219-
}
220-
}
214+
for (unsigned int ibx = 0; ibx < DEPTH_BX; ++ibx) {
215+
for (unsigned int i = 0; i < nentries_[ibx]; ++i) {
216+
edm::LogVerbatim("L1trackHLS") << ibx << " " << i << " ";
217+
print_entry(ibx,i);
218+
}
219+
}
221220
}
222221

223222
static constexpr int getWidth() {return DataType::getWidth();}

0 commit comments

Comments
 (0)