Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix Future L1 Track SW + bugs in HLS memory classes. #347

Merged
merged 19 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TestBenches/FileReadUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ unsigned int compareMemWithMemPage(const MemType& memory_ref, const MemType& mem
constexpr int lsb = (LSB >= 0 && MSB >= LSB) ? LSB : 0;
constexpr int msb = (LSB >= 0 && MSB >= LSB) ? MSB : MemType::getWidth() - 1;

for (unsigned int ipage = 0; ipage < 4; ++ipage) {
for (unsigned int ipage = 0; ipage < memory_ref.getNPage(); ++ipage) {
//FIXME
for (unsigned int i = 0; i < memory_ref.getDepth()/4; ++i) {
for (unsigned int i = 0; i < memory_ref.getDepth(); ++i) {
const auto data_ref_raw = memory_ref.read_mem(ievt,i,ipage).raw();
const auto data_com_raw = memory.read_mem(ievt,i,ipage).raw();
const auto data_ref = data_ref_raw.range(msb,lsb);
Expand Down
11 changes: 5 additions & 6 deletions TrackletAlgorithm/MatchProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ template<TF::layerDisk Layer, TF::phiRegion PHI> constexpr uint32_t NPageSum();

#include "MatchProcessor_parameters.h"

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

#pragma HLS inline
Expand Down Expand Up @@ -1180,7 +1180,7 @@ constexpr unsigned kNbitsrzbinMPDisk = kNbitsrzbin + 1;

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

Expand Down Expand Up @@ -1458,7 +1458,7 @@ void MatchProcessor(BXType bx,

if (hasMatch_save) {
isMatch = newtracklet_save ? ap_uint<1>(0) : isMatch;
MatchCalculator<ASTYPE, APTYPE, VMSMEType, FMTYPE, maxFullMatchCopies, LAYER, PHISEC>
MatchCalculator<ASTYPE, APTYPE, VMSMEType, FMTYPE, maxFullMatchVariants, LAYER, PHISEC>
(bx, newtracklet_save, isMatch, savedMatch, best_delta_z, best_delta_phi, best_delta_rphi, best_delta_r, allstub, allproj_save, stubindex_save,
fullmatch);
}
Expand All @@ -1483,7 +1483,6 @@ void MatchProcessor(BXType bx,
newtracklet_save = newtracklet;
allproj_save = allproj;
stubindex_save = stubindex;

} //end MC if


Expand Down
97 changes: 48 additions & 49 deletions TrackletAlgorithm/MemoryTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,41 @@ template<class DataType, unsigned int NBIT_BX, unsigned int NBIT_ADDR>
// (1<<NBIT_ADDR): depth of the memory for each BX
class MemoryTemplate
{
private:
#ifdef CMSSW_GIT_HASH
static constexpr unsigned int NBIT_BX = 0;
#endif

public:
static constexpr unsigned int DEPTH_BX = 1<<NBIT_BX;
static constexpr unsigned int DEPTH_ADDR = 1<<NBIT_ADDR;

typedef typename DataType::BitWidths BitWidths;
typedef ap_uint<NBIT_BX> BunchXingT;
typedef ap_uint<NBIT_ADDR> NEntryT;

protected:

DataType dataarray_[1<<NBIT_BX][1<<NBIT_ADDR]; // data array
NEntryT nentries_[1<<NBIT_BX]; // number of entries
DataType dataarray_[DEPTH_BX][DEPTH_ADDR]; // data array
NEntryT nentries_[DEPTH_BX]; // number of entries

public:

unsigned int getDepth() const {return (1<<NBIT_ADDR);}
unsigned int getNBX() const {return (1<<NBIT_BX);}
unsigned int getDepth() const {return DEPTH_ADDR;}
unsigned int getNBX() const {return DEPTH_BX;}

NEntryT getEntries(BunchXingT bx) const {
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
return nentries_[bx];
return nentries_[bx];
}

const DataType (&get_mem() const)[1<<NBIT_BX][1<<NBIT_ADDR] {return dataarray_;}
const DataType (&get_mem() const)[DEPTH_BX][DEPTH_ADDR] {return dataarray_;}

DataType read_mem(BunchXingT ibx, ap_uint<NBIT_ADDR> index) const
{
// TODO: check if valid
if(!NBIT_BX) ibx = 0;
return dataarray_[ibx][index];
// TODO: check if valid
if(!NBIT_BX) ibx = 0;
return dataarray_[ibx][index];
}

template<class SpecType>
Expand All @@ -72,7 +76,7 @@ class MemoryTemplate
#ifdef __SYNTHESIS__
0;
#else
nentries_[ibx];
nentries_[ibx];
#endif
return write_mem(ibx,data,addr_index);
}
Expand All @@ -83,10 +87,10 @@ class MemoryTemplate
#pragma HLS inline
if(!NBIT_BX) ibx = 0;
static_assert(
std::is_same<DataType, SpecType>::value
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
, "Invalid conversion between data types");
std::is_same<DataType, SpecType>::value
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
|| (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
, "Invalid conversion between data types");
DataType sameData(data.raw());
return write_mem(ibx,sameData,addr_index);
}
Expand All @@ -98,7 +102,7 @@ class MemoryTemplate
#ifdef __SYNTHESIS__
0;
#else
nentries_[ibx];
nentries_[ibx];
#endif
return write_mem(ibx,data,addr_index);
}
Expand All @@ -108,7 +112,7 @@ class MemoryTemplate
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
#pragma HLS inline
if(!NBIT_BX) ibx = 0;
if (addr_index < (1<<NBIT_ADDR)) {
if (addr_index < DEPTH_ADDR) {
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
//The vhd memory implementation will write to the correct address!!
dataarray_[ibx][0] = data;
Expand All @@ -126,28 +130,23 @@ class MemoryTemplate
}
}

bool write_mem_new(BunchXingT ibx, DataType data, NEntryT addr_index)
bool write_mem_new(BunchXingT ibx, DataType data, ap_uint<1> overwrite)
{
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
#pragma HLS inline
if(!NBIT_BX) ibx = 0;
if (addr_index < (1<<NBIT_ADDR)) {
//dataarray_[ibx][addr_index] = data;
if (nentries_[ibx] < DEPTH_ADDR) {
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
//The vhd memory implementation will write to the correct address!!
dataarray_[ibx][0] = data;
#else
if(addr_index == 0) {
dataarray_[ibx][nentries_[ibx]++] = data;
if(overwrite == 0) {
dataarray_[ibx][nentries_[ibx]++] = data;
} else {
dataarray_[ibx][nentries_[ibx]-1] = data;
dataarray_[ibx][nentries_[ibx]-1] = data;
}
#endif

#ifdef CMSSW_GIT_HASH
nentries_[ibx] = addr_index + 1;
#endif

return true;
} else {
return false;
Expand All @@ -158,17 +157,17 @@ class MemoryTemplate
#ifndef __SYNTHESIS__
MemoryTemplate()
{
clear();
clear();
}

~MemoryTemplate(){}

void clear()
{
DataType data("0",16);
MEM_RST: for (size_t ibx=0; ibx<(1<<NBIT_BX); ++ibx) {
MEM_RST: for (size_t ibx=0; ibx<DEPTH_BX; ++ibx) {
nentries_[ibx] = 0;
for (size_t addr=0; addr<(1<<NBIT_ADDR); ++addr) {
for (size_t addr=0; addr<DEPTH_ADDR; ++addr) {
write_mem(ibx,data,addr);
}
}
Expand All @@ -177,47 +176,47 @@ class MemoryTemplate
// write memory from text file
bool write_mem(BunchXingT ibx, const char* datastr, int base=16)
{
if(!NBIT_BX) ibx = 0;
DataType data(datastr, base);
NEntryT nent = nentries_[ibx];
bool success = write_mem(ibx, data, nent);
if(!NBIT_BX) ibx = 0;
DataType data(datastr, base);
NEntryT nent = nentries_[ibx];
bool success = write_mem(ibx, data, nent);

return success;
return success;
}

bool write_mem(BunchXingT ibx, const std::string datastr, int base=16)
bool write_mem(BunchXingT ibx, const std::string& datastr, int base=16)
{
return write_mem(ibx, datastr.c_str(), base);
return write_mem(ibx, datastr.c_str(), base);
}

// print memory contents
void print_data(const DataType data) const
{
edm::LogVerbatim("L1trackHLS") << std::hex << data.raw() << std::endl;
// TODO: overload '<<' in data class
// TODO: overload '<<' in data class
}

void print_entry(BunchXingT bx, NEntryT index) const
{
print_data(dataarray_[bx][index]);
print_data(dataarray_[bx][index]);
}

void print_mem(BunchXingT bx) const
{
for (unsigned int i = 0; i < nentries_[bx]; ++i) {
edm::LogVerbatim("L1trackHLS") << bx << " " << i << " ";
print_entry(bx,i);
}
for (unsigned int i = 0; i < nentries_[bx]; ++i) {
edm::LogVerbatim("L1trackHLS") << bx << " " << i << " ";
print_entry(bx,i);
}
}

void print_mem() const
{
for (unsigned int ibx = 0; ibx < (1<<NBIT_BX); ++ibx) {
for (unsigned int i = 0; i < nentries_[ibx]; ++i) {
edm::LogVerbatim("L1trackHLS") << ibx << " " << i << " ";
print_entry(ibx,i);
}
}
for (unsigned int ibx = 0; ibx < DEPTH_BX; ++ibx) {
for (unsigned int i = 0; i < nentries_[ibx]; ++i) {
edm::LogVerbatim("L1trackHLS") << ibx << " " << i << " ";
print_entry(ibx,i);
}
}
}

static constexpr int getWidth() {return DataType::getWidth();}
Expand Down
Loading
Loading