Skip to content

Commit

Permalink
Correct bug so that we have correct stub bend size for TE VMStubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders Ryd committed Nov 5, 2024
1 parent b41f602 commit 8dbc34e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions TestBenches/TrackletProcessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::cout<<module_name[MODULE_];
const auto nOuterStubMems = tb.nFiles(outerStubPattern);
vector<AllStubInnerMemory<InnerStubType> > innerStubs(nInnerStubMems);
vector<AllStubMemory<OuterStubType> > outerStubs(nOuterStubMems);
vector<VMStubMemory<OuterStubType, kNbitsrzbin, kNbitsphibin, NCOPY> > outervmStubs(nOuterVMStubMems);
vector<VMStubMemory<OuterStubType, kNbitsrzbin, kNbitsphibin, NCOPY, true> > outervmStubs(nOuterVMStubMems);

// output memories
TrackletParameterMemory tpar;
Expand Down Expand Up @@ -145,7 +145,7 @@ std::cout<<module_name[MODULE_];
for (unsigned i = 0; i < nOuterStubMems; i++)
writeMemFromFile<AllStubMemory<OuterStubType> >(outerStubs[i], fin_outerStubs.at(i), ievt);
for (unsigned i = 0; i < nOuterVMStubMems; i++)
writeMemFromFile<VMStubMemory<OuterStubType, kNbitsrzbin, kNbitsphibin, NCOPY>>(outervmStubs[i], fin_outervmStubs.at(i), ievt);
writeMemFromFile<VMStubMemory<OuterStubType, kNbitsrzbin, kNbitsphibin, NCOPY, true>>(outervmStubs[i], fin_outervmStubs.at(i), ievt);

// clear all output memories before starting
tpar.clear();
Expand Down
4 changes: 2 additions & 2 deletions TestBenches/VMRouterCM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main() {
static AllStubMemory<outputType> memoriesAS[numASCopies];
static AllStubInnerMemory<outputType> memoriesASInner[numASInnerCopies];
static VMStubMemory<outputType, kNbitsrzbinME, kNbitsphibin, kNMatchEngines> memoryME;
static VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk]> memoriesTEO[numTEOCopies];
static VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk], true> memoriesTEO[numTEOCopies];


///////////////////////////
Expand Down Expand Up @@ -147,7 +147,7 @@ int main() {
//TE Outer memories
if (nVMSTE) {
for (unsigned int i = 0; i < nVMSTE; i++) {
err += compareBinnedMemCMWithFile<VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk]>>(memoriesTEO[i], fout_vmstubte[i], ievt, "VMStubTEOuter", truncation);
err += compareBinnedMemCMWithFile<VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk], true>>(memoriesTEO[i], fout_vmstubte[i], ievt, "VMStubTEOuter", truncation);
}
}
} // End of event loop
Expand Down
4 changes: 2 additions & 2 deletions TrackletAlgorithm/TrackletEngineUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TrackletEngineUnit {
kNBitsPTLutOuter=(Seed==TF::L5L6||Seed==TF::L1D1||Seed==TF::L2D1||Seed==TF::D1D2||Seed==TF::D3D4)?1024:(Seed==TF::L1L2||Seed==TF::L2L3)?256:512
};

typedef ap_uint<VMStub<VMSType>::kVMSIDSize+AllStub<innerRegion>::kAllStubSize+TrackletParameters::kTParPhiRegionSize+kNBits_MemAddr> STUBID;
typedef ap_uint<VMStub<VMSType, true>::kVMSIDSize+AllStub<innerRegion>::kAllStubSize+TrackletParameters::kTParPhiRegionSize+kNBits_MemAddr> STUBID;
typedef ap_uint<kNBitsNegDiskSize> NEGDISK;
typedef ap_uint<kNBits_MemAddrBinned> NSTUBS;
typedef ap_uint<kNBitsBuffer> INDEX;
Expand Down Expand Up @@ -178,7 +178,7 @@ void write(STUBID stubs) {
ap_uint<1> next__, next___;
PHIBIN ireg__, ireg___;

VMStub<VMSType> outervmstub__, outervmstub___;
VMStub<VMSType, true> outervmstub__, outervmstub___;

NSTUBS ns[16];

Expand Down
10 changes: 5 additions & 5 deletions TrackletAlgorithm/TrackletProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ TF::seed Seed, // seed layer combination (TP::L1L2, TP::L3L4, etc.)
uint16_t N // maximum number of steps
> void
TrackletProcessor(
const BXType bx, BXType& bx_o, const LUTTYPE lut[lutsize], const AllStubInnerMemory<InnerRegion<Seed>()> innerStubs[NASMemInner], const AllStubMemory<OuterRegion<Seed>()>* outerStubs, const VMStubMemory<OuterRegion<Seed>(),kNbitsrzbin,kNbitsphibin,NVMSTECopy>* outerVMStubs, TrackletParameterMemory * const trackletParameters, TrackletProjectionMemory<BARRELPS> projout_barrel_ps[TP::N_PROJOUT_BARRELPS], TrackletProjectionMemory<BARREL2S> projout_barrel_2s[TP::N_PROJOUT_BARREL2S], TrackletProjectionMemory<DISK> projout_disk[TP::N_PROJOUT_DISK]
const BXType bx, BXType& bx_o, const LUTTYPE lut[lutsize], const AllStubInnerMemory<InnerRegion<Seed>()> innerStubs[NASMemInner], const AllStubMemory<OuterRegion<Seed>()>* outerStubs, const VMStubMemory<OuterRegion<Seed>(),kNbitsrzbin,kNbitsphibin,NVMSTECopy, true>* outerVMStubs, TrackletParameterMemory * const trackletParameters, TrackletProjectionMemory<BARRELPS> projout_barrel_ps[TP::N_PROJOUT_BARRELPS], TrackletProjectionMemory<BARREL2S> projout_barrel_2s[TP::N_PROJOUT_BARREL2S], TrackletProjectionMemory<DISK> projout_disk[TP::N_PROJOUT_DISK]
)
{
constexpr bool diskSeed = (Seed == TF::D1D2 || Seed == TF::D3D4);
Expand Down Expand Up @@ -728,7 +728,7 @@ TF::seed Seed, // seed layer combination (TP::L1L2, TP::L3L4, etc.)
const ap_uint<1>* stubptinnertmp = TP::getPTInnerLUT<Seed,iTC>();
static const TPRegionLUT<Seed> regionLUT(stubptinnertmp, iAllstub);

constexpr unsigned int NfinephiBits=NBitsPhiRegion+TrackletEngineUnit<Seed,iTC,innerASType,OuterRegion<Seed>()>::kNBitsPhiBins+VMStubBase<OuterRegion<Seed>()>::kVMSFinePhiSize;
constexpr unsigned int NfinephiBits=NBitsPhiRegion+TrackletEngineUnit<Seed,iTC,innerASType,OuterRegion<Seed>()>::kNBitsPhiBins+VMStubBase<OuterRegion<Seed>(), true>::kVMSFinePhiSize;

static TEBuffer<Seed,iTC,innerASType,OuterRegion<Seed>()> tebuffer;
static_assert(TP::nASMemInner<Seed, iTC>() <= 3, "Only handling up to three inner AS memories");
Expand Down Expand Up @@ -801,7 +801,7 @@ TF::seed Seed, // seed layer combination (TP::L1L2, TP::L3L4, etc.)
teureadindex[k] = 0;
}
//quantities looked up in LUT
typename VMStub<OuterRegion<Seed>()>::VMSFINEZ rzfinebinfirst,rzdiffmax;
typename VMStub<OuterRegion<Seed>(), true>::VMSFINEZ rzfinebinfirst,rzdiffmax;
typename TrackletEngineUnit<Seed,iTC,innerASType,OuterRegion<Seed>()>::RZBIN start;
ap_uint<1> usenext;
istep_loop: for(unsigned istep=0;istep<N;istep++) {
Expand Down Expand Up @@ -891,8 +891,8 @@ teunits[k].idle_;

typename TrackletEngineUnit<Seed,iTC,innerASType,OuterRegion<Seed>()>::INDEX writeindexnext=teuwriteindex[k]+1;

const typename VMStub<OuterRegion<Seed>()>::VMSFINEPHI& finephi = teunits[k].outervmstub___.getFinePhi();
const ap_uint<1+VMStubBase<OuterRegion<Seed>()>::kVMSFineZSize>& rzbin = (teunits[k].next___, teunits[k].outervmstub___.getFineZ());
const typename VMStub<OuterRegion<Seed>(), true>::VMSFINEPHI& finephi = teunits[k].outervmstub___.getFinePhi();
const ap_uint<1+VMStubBase<OuterRegion<Seed>(), true>::kVMSFineZSize>& rzbin = (teunits[k].next___, teunits[k].outervmstub___.getFineZ());


ap_uint<NfinephiBits> outerfinephi = (iAllstub, teunits[k].ireg___, finephi);
Expand Down
8 changes: 4 additions & 4 deletions TrackletAlgorithm/VMRouterCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void VMRouterCM(const BXType bx, BXType& bx_o,
// ME memories
VMStubMemory<OutType, rzSizeME, phiRegSize, kNMatchEngines> *memoryME,
// TE Outer memories
VMStubMemory<OutType, rzSizeTE, phiRegSize, kNTEUnitsLayerDisk[(Layer) ? Layer-1 : Disk+5]> memoriesTEO[]) {
VMStubMemory<OutType, rzSizeTE, phiRegSize, kNTEUnitsLayerDisk[(Layer) ? Layer-1 : Disk+5], true> memoriesTEO[]) {

#pragma HLS inline
#pragma HLS array_partition variable=inputStubs complete dim=1
Expand Down Expand Up @@ -411,9 +411,9 @@ void VMRouterCM(const BXType bx, BXType& bx_o,
int slotTE; // The bin the stub is going to be put in, in the memory

// Create the TE Outer stub to save
VMStub<OutType> stubTEO = (Layer) ?
createVMStub<VMStub<OutType>, InType, OutType, Layer, Disk, false>(stub, i, negDisk, METable, phiCorrTable, slotTE) :
createVMStub<VMStub<OutType>, InType, OutType, Layer, Disk, false>(stub, i, negDisk, TEDiskTable, phiCorrTable, slotTE);
VMStub<OutType, true> stubTEO = (Layer) ?
createVMStub<VMStub<OutType, true>, InType, OutType, Layer, Disk, false>(stub, i, negDisk, METable, phiCorrTable, slotTE) :
createVMStub<VMStub<OutType, true>, InType, OutType, Layer, Disk, false>(stub, i, negDisk, TEDiskTable, phiCorrTable, slotTE);

// Write stub to all TE memory copies
for (int n = 0; n < nTEOCopies; n++) {
Expand Down
44 changes: 22 additions & 22 deletions TrackletAlgorithm/VMStubMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// stub data + a pointer to the full precision stub data in the AllStubMemory.

// VMStubBase is where we define the bit widths, which depend on the class template parameter.
template<int VMSType> class VMStubBase {};
template<int VMSType, bool TE = false> class VMStubBase {};

template<>
class VMStubBase<BARRELPS>
template<bool TE>
class VMStubBase<BARRELPS, TE>
{
public:
enum BitWidths {
Expand All @@ -26,8 +26,8 @@ class VMStubBase<BARRELPS>
};
};

template<>
class VMStubBase<BARREL2S>
template<bool TE>
class VMStubBase<BARREL2S, TE>
{
public:
enum BitWidths {
Expand All @@ -41,45 +41,45 @@ class VMStubBase<BARREL2S>
};
};

template<>
class VMStubBase<DISK>
template<bool TE>
class VMStubBase<DISK, TE>
{
public:
enum BitWidths {
// Bit sizes for VMStubMemory fields
kVMSFineZSize = 3,
kVMSFinePhiSize = 3,
kVMSBendSize = 4,
kVMSBendSize = TE ? 3 : 4,
kVMSIDSize = 7,
// Bit size for full VMStubMemory
kVMStubSize = kVMSFineZSize + kVMSFinePhiSize + kVMSBendSize + kVMSIDSize
};
};

// Data object definition
template<int VMSType>
class VMStub : public VMStubBase<VMSType>
template<int VMSType, bool TE = false>
class VMStub : public VMStubBase<VMSType, TE>
{
public:
enum BitLocations {
// The location of the least significant bit (LSB) and most significant bit (MSB) in the VMStubMemory word for different fields
kVMSFineZLSB = 0,
kVMSFineZMSB = kVMSFineZLSB + VMStubBase<VMSType>::kVMSFineZSize - 1,
kVMSFineZMSB = kVMSFineZLSB + VMStubBase<VMSType, TE>::kVMSFineZSize - 1,
kVMSFinePhiLSB = kVMSFineZMSB + 1,
kVMSFinePhiMSB = kVMSFinePhiLSB + VMStubBase<VMSType>::kVMSFinePhiSize - 1,
kVMSFinePhiMSB = kVMSFinePhiLSB + VMStubBase<VMSType, TE>::kVMSFinePhiSize - 1,
kVMSBendLSB = kVMSFinePhiMSB + 1,
kVMSBendMSB = kVMSBendLSB + VMStubBase<VMSType>::kVMSBendSize - 1,
kVMSBendMSB = kVMSBendLSB + VMStubBase<VMSType, TE>::kVMSBendSize - 1,
kVMSIDLSB = kVMSBendMSB + 1,
kVMSIDMSB = kVMSIDLSB + VMStubBase<VMSType>::kVMSIDSize - 1
kVMSIDMSB = kVMSIDLSB + VMStubBase<VMSType, TE>::kVMSIDSize - 1
};

typedef ap_uint<VMStubBase<VMSType>::kVMSIDSize> VMSID;
typedef ap_uint<VMStubBase<VMSType>::kVMSBendSize> VMSBEND;
typedef ap_uint<VMStubBase<VMSType>::kVMSBendSize - 1> VMSBENDPSDISK;
typedef ap_uint<VMStubBase<VMSType>::kVMSFineZSize> VMSFINEZ;
typedef ap_uint<VMStubBase<VMSType>::kVMSFinePhiSize> VMSFINEPHI;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMSIDSize> VMSID;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMSBendSize> VMSBEND;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMSBendSize - 1> VMSBENDPSDISK;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMSFineZSize> VMSFINEZ;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMSFinePhiSize> VMSFINEPHI;

typedef ap_uint<VMStubBase<VMSType>::kVMStubSize> VMStubData;
typedef ap_uint<VMStubBase<VMSType, TE>::kVMStubSize> VMStubData;

// Constructors
VMStub(const VMStubData& newdata):
Expand All @@ -102,7 +102,7 @@ class VMStub : public VMStubBase<VMSType>
#endif

// Getter
static constexpr int getWidth() {return VMStubBase<VMSType>::kVMStubSize;}
static constexpr int getWidth() {return VMStubBase<VMSType, TE>::kVMStubSize;}

VMStubData raw() const {return data_;}

Expand Down Expand Up @@ -160,6 +160,6 @@ class VMStub : public VMStubBase<VMSType>
};

// Memory definition
template<int VMSType, int RZSize, int PhiRegSize, unsigned int NCOPY > using VMStubMemory = MemoryTemplateBinnedCM<VMStub<VMSType>, 1, 4+RZSize+PhiRegSize, RZSize+PhiRegSize, PhiRegSize, NCOPY>;
template<int VMSType, int RZSize, int PhiRegSize, unsigned int NCOPY, bool TE = false > using VMStubMemory = MemoryTemplateBinnedCM<VMStub<VMSType, TE>, 1, 4+RZSize+PhiRegSize, RZSize+PhiRegSize, PhiRegSize, NCOPY>;

#endif
4 changes: 2 additions & 2 deletions emData/generate_TP.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class ProjoutIndexDisk(Enum):
" BXType& bx_o,\n"
" const AllStubInnerMemory<InnerRegion<TF::" + str(seed) + ">()> innerStubs[TP::nASMemInner<TF::" + str(seed) + ", TP::" + iTC + ">()],\n"
" const AllStubMemory<OuterRegion<TF::" + str(seed) + ">()>* outerStubs,\n"
" const VMStubMemory<OuterRegion<TF::" + str(seed) + ">(), kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[TF::"+seed[2:]+"]>* outerVMStubs,\n"
" const VMStubMemory<OuterRegion<TF::" + str(seed) + ">(), kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[TF::"+seed[2:]+"], true>* outerVMStubs,\n"
" TrackletParameterMemory * trackletParameters,\n"
" TrackletProjectionMemory<BARRELPS> projout_barrel_ps[],\n"
" TrackletProjectionMemory<BARREL2S> projout_barrel_2s[],\n"
Expand All @@ -316,7 +316,7 @@ class ProjoutIndexDisk(Enum):
" BXType& bx_o,\n"
" const AllStubInnerMemory<InnerRegion<TF::" + str(seed) + ">()> innerStubs[TP::nASMemInner<TF::" + str(seed) + ", TP::" + iTC + ">()],\n"
" const AllStubMemory<OuterRegion<TF::" + str(seed) + ">()>* outerStubs ,\n"
" const VMStubMemory<OuterRegion<TF::" + str(seed) + ">(), kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[TF::"+ seed[2:] +"]>* outerVMStubs,\n"
" const VMStubMemory<OuterRegion<TF::" + str(seed) + ">(), kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[TF::"+ seed[2:] +"], true>* outerVMStubs,\n"
" TrackletParameterMemory * trackletParameters,\n"
" TrackletProjectionMemory<BARRELPS> projout_barrel_ps[TP::N_PROJOUT_BARRELPS],\n"
" TrackletProjectionMemory<BARREL2S> projout_barrel_2s[TP::N_PROJOUT_BARREL2S],\n"
Expand Down
4 changes: 2 additions & 2 deletions emData/generate_VMRCM.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def writeTopHeader(vmr, output_dir):
" AllStubMemory<outputType> memoriesAS[numASCopies],\n"
+ (" AllStubInnerMemory<outputType> memoriesASInner[numASInnerCopies],\n" if has_allstub_inner[layerdisk] else "") +\
" VMStubMemory<outputType, kNbitsrzbinME, kNbitsphibin, kNMatchEngines> *memoryME" + (",\n" if has_vmste_outer[layerdisk] else "")
+ (" VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk]> memoriesTEO[numTEOCopies]\n" if has_vmste_outer[layerdisk] else "") +\
+ (" VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk], true> memoriesTEO[numTEOCopies]\n" if has_vmste_outer[layerdisk] else "") +\
" );\n"
"\n"
"#endif // TopFunctions_%s_h\n" % file_name
Expand Down Expand Up @@ -418,7 +418,7 @@ def writeTopFile(vmr, num_inputs, num_inputs_disk2s, output_dir):
" AllStubMemory<outputType> memoriesAS[numASCopies],\n"
+ (" AllStubInnerMemory<outputType> memoriesASInner[numASInnerCopies],\n" if has_allstub_inner[layerdisk] else "") +\
" VMStubMemory<outputType, kNbitsrzbinME, kNbitsphibin, kNMatchEngines> *memoryME" + (",\n" if has_vmste_outer[layerdisk] else "")
+ (" VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk]> memoriesTEO[numTEOCopies]\n" if has_vmste_outer[layerdisk] else "") +\
+ (" VMStubMemory<outputType, kNbitsrzbin, kNbitsphibin, kNTEUnitsLayerDisk[layerdisk], true> memoriesTEO[numTEOCopies]\n" if has_vmste_outer[layerdisk] else "") +\
" ) {\n"
"\n"
"// Takes 2 clock cycles before one gets data, used at high frequencies\n"
Expand Down

0 comments on commit 8dbc34e

Please sign in to comment.