CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Attributes
trklet::VarInv Class Reference

#include <imath.h>

Inheritance diagram for trklet::VarInv:
trklet::VarBase

Public Types

enum  mode { pos, neg, both }
 

Public Member Functions

int addr_to_ival (int addr)
 
int gen_inv (int i)
 
void initLUT (double offset)
 
double Ioffset ()
 
int ival_to_addr (int ival)
 
void local_calculate () override
 
double offset ()
 
void print (std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
 
void print (std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0) override
 
void set_mode (mode m)
 
 VarInv (imathGlobals *globals, std::string name, VarBase *p1, double offset, int nbits, int n, unsigned int shift, mode m, int nbaddr=-1)
 
void writeLUT (std::ofstream &fs) const
 
void writeLUT (std::ofstream &fs, Verilog) const
 
void writeLUT (std::ofstream &fs, HLS) const
 
 ~VarInv () override
 
- Public Member Functions inherited from trklet::VarBase
void add_cut (VarCut *cut, const bool call_set_cut_var=true)
 
void add_delay (int i)
 
void add_latency (unsigned int l)
 
void analyze ()
 
void calcDebug (int debug_level, long int ival_prev, bool &all_ok)
 
bool calculate (int debug_level=0)
 
VarBasecut_var ()
 
std::string dump ()
 
void dump_msg ()
 
double fval () const
 
bool has_delay (int i)
 
void inputs (std::vector< VarBase *> *vd)
 
long int ival () const
 
double K () const
 
std::map< std::string, int > Kmap () const
 
std::string kstring () const
 
int latency () const
 
bool local_passes () const
 
void makeready ()
 
double maxval () const
 
double minval () const
 
std::string name () const
 
int nbits () const
 
std::string op () const
 
VarBasep1 () const
 
VarBasep2 () const
 
VarBasep3 () const
 
void passes (std::map< const VarBase *, std::vector< bool > > &passes, const std::map< const VarBase *, std::vector< bool > > *const previous_passes=nullptr) const
 
int pipe_counter ()
 
std::string pipe_delays (const int step)
 
void pipe_increment ()
 
void print_all (std::ofstream &fs, Verilog)
 
void print_all (std::ofstream &fs, HLS)
 
void print_cuts (std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, Verilog, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
 
void print_cuts (std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, HLS, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
 
void print_step (int step, std::ofstream &fs, Verilog)
 
void print_step (int step, std::ofstream &fs, HLS)
 
void print_truncation (std::string &t, const std::string &o1, const int ps, Verilog) const
 
void print_truncation (std::string &t, const std::string &o1, const int ps, HLS) const
 
double range () const
 
void reset ()
 
int shift () const
 
int step () const
 
 VarBase (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
 
virtual ~VarBase ()
 

Protected Attributes

unsigned int ashift_
 
int * LUT
 
mode m_
 
unsigned int mask_
 
int n_
 
int nbaddr_
 
int Nelements_
 
double offset_
 
unsigned int shift_
 
- Protected Attributes inherited from trklet::VarBase
VarBasecut_var_
 
std::vector< VarBase * > cuts_
 
double fval_
 
imathGlobalsglobals_
 
long int ival_
 
double K_
 
std::map< std::string, int > Kmap_
 
int latency_
 
double maxval_
 
double minval_
 
std::string name_
 
int nbits_
 
std::string op_
 
VarBasep1_
 
VarBasep2_
 
VarBasep3_
 
int pipe_counter_
 
std::vector< int > pipe_delays_
 
bool readytoanalyze_
 
bool readytoprint_
 
int step_
 
bool usedasinput_
 
double val_
 

Additional Inherited Members

- Static Public Member Functions inherited from trklet::VarBase
static void design_print (const std::vector< VarBase *> &v, std::ofstream &fs, Verilog)
 
static void design_print (const std::vector< VarBase *> &v, std::ofstream &fs, HLS)
 
static void hls_print (const std::vector< VarBase *> &v, std::ofstream &fs)
 
static std::string itos (int i)
 
static std::string pipe_delay (VarBase *v, int nbits, int delay)
 
static std::string pipe_delay_wire (VarBase *v, std::string name_delayed, int nbits, int delay)
 
static void verilog_print (const std::vector< VarBase *> &v, std::ofstream &fs)
 
- Static Public Attributes inherited from trklet::VarBase
static struct trklet::VarBase::HLS hls
 
static struct trklet::VarBase::Verilog verilog
 

Detailed Description

Definition at line 956 of file imath.h.

Member Enumeration Documentation

◆ mode

Enumerator
pos 
neg 
both 

Definition at line 958 of file imath.h.

Constructor & Destructor Documentation

◆ VarInv()

trklet::VarInv::VarInv ( imathGlobals globals,
std::string  name,
VarBase p1,
double  offset,
int  nbits,
int  n,
unsigned int  shift,
mode  m,
int  nbaddr = -1 
)
inline

Definition at line 960 of file imath.h.

References addr_to_ival(), ashift_, reco::HaloData::both, gen_inv(), mps_fire::i, testProducerWithPsetDescEmpty_cfi::i1, createfilelist::int, trklet::VarBase::K(), trklet::VarBase::K_, trklet::VarBase::Kmap(), trklet::VarBase::Kmap_, visualization-live-secondInstance_cfg::m, m_, mask_, dqmiodumpmetadata::n, n_, nbaddr_, trklet::VarBase::nbits(), trklet::VarBase::nbits_, Nelements_, offset(), offset_, trklet::VarBase::op_, trklet::VarBase::p1(), trklet::VarBase::p1_, conifer::pow(), trklet::VarBase::shift(), and shift_.

969  : VarBase(globals, name, p1, nullptr, nullptr, LUT_LATENCY) {
970  op_ = "inv";
971  offset_ = offset;
972  nbits_ = nbits;
973  n_ = n;
974  shift_ = shift;
975  m_ = m;
976  if (nbaddr < 0)
977  nbaddr = p1->nbits();
978  nbaddr_ = nbaddr - shift;
979  if (m_ != mode::both)
980  nbaddr_--;
981  Nelements_ = 1 << nbaddr_;
982  mask_ = Nelements_ - 1;
983  ashift_ = sizeof(int) * 8 - nbaddr_;
984 
985  const std::map<std::string, int> map1 = p1->Kmap();
986  for (const auto &it : map1)
987  Kmap_[it.first] = -it.second;
988  Kmap_["2"] = Kmap_["2"] - n;
989  K_ = pow(2, -n) / p1->K();
990 
991  LUT = new int[Nelements_];
992  double offsetI = lround(offset_ / p1_->K());
993  for (int i = 0; i < Nelements_; ++i) {
994  int i1 = addr_to_ival(i);
995  LUT[i] = gen_inv(offsetI + i1);
996  }
997  }
std::string name() const
Definition: imath.h:208
int gen_inv(int i)
Definition: imath.h:1024
unsigned int mask_
Definition: imath.h:1047
int nbits() const
Definition: imath.h:244
VarBase * p1_
Definition: imath.h:298
double offset()
Definition: imath.h:1002
constexpr int pow(int x)
Definition: conifer.h:24
int shift() const
Definition: imath.h:248
int addr_to_ival(int addr)
Definition: imath.h:1013
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:162
std::string op_
Definition: imath.h:301
int Nelements_
Definition: imath.h:1049
double offset_
Definition: imath.h:1043
unsigned int ashift_
Definition: imath.h:1048
VarBase * p1() const
Definition: imath.h:210
std::map< std::string, int > Kmap() const
Definition: imath.h:245
#define LUT_LATENCY
Definition: imath.h:141
double K() const
Definition: imath.h:247
std::map< std::string, int > Kmap_
Definition: imath.h:314
double K_
Definition: imath.h:313
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
unsigned int shift_
Definition: imath.h:1046

◆ ~VarInv()

trklet::VarInv::~VarInv ( )
inlineoverride

Definition at line 998 of file imath.h.

References LUT.

998 { delete[] LUT; }
int * LUT
Definition: imath.h:1052

Member Function Documentation

◆ addr_to_ival()

int trklet::VarInv::addr_to_ival ( int  addr)
inline

Definition at line 1013 of file imath.h.

References generateTowerEtThresholdLUT::addr, ashift_, cms::cuda::assert(), l1t::bitShift(), reco::HaloData::both, m_, Nelements_, and shift_.

Referenced by initLUT(), and VarInv().

1013  {
1014  switch (m_) {
1015  case mode::pos:
1016  return l1t::bitShift(addr, shift_);
1017  case mode::neg:
1018  return l1t::bitShift((addr - Nelements_), shift_);
1019  case mode::both:
1020  return l1t::bitShift(addr, ashift_) >> (ashift_ - shift_);
1021  }
1022  assert(0);
1023  }
assert(be >=bs)
int Nelements_
Definition: imath.h:1049
unsigned int ashift_
Definition: imath.h:1048
unsigned int shift_
Definition: imath.h:1046
int bitShift(int num, int bits)
Definition: BitShift.h:6

◆ gen_inv()

int trklet::VarInv::gen_inv ( int  i)
inline

Definition at line 1024 of file imath.h.

References mps_fire::i, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, createfilelist::int, n_, trklet::VarBase::nbits_, and shift_.

Referenced by initLUT(), and VarInv().

1024  {
1025  unsigned int ms = sizeof(int) * 8 - nbits_;
1026  int lut = 0;
1027  if (i > 0) {
1028  int i1 = i + (1 << shift_) - 1;
1029  int lut1 = (lround((1 << n_) / i) << ms) >> ms;
1030  int lut2 = (lround((1 << n_) / (i1)) << ms) >> ms;
1031  lut = 0.5 * (lut1 + lut2);
1032  } else if (i < -1) {
1033  int i1 = i + (1 << shift_) - 1;
1034  int i2 = i;
1035  int lut1 = (lround((1 << n_) / i1) << ms) >> ms;
1036  int lut2 = (lround((1 << n_) / i2) << ms) >> ms;
1037  lut = 0.5 * (lut1 + lut2);
1038  }
1039  return lut;
1040  }
unsigned int shift_
Definition: imath.h:1046

◆ initLUT()

void VarInv::initLUT ( double  offset)

Definition at line 142 of file imath.cc.

References addr_to_ival(), gen_inv(), mps_fire::i, testProducerWithPsetDescEmpty_cfi::i1, trklet::VarBase::K(), Nelements_, offset(), offset_, and trklet::VarBase::p1_.

Referenced by trklet::IMATH_TrackletCalculator::IMATH_TrackletCalculator(), trklet::IMATH_TrackletCalculatorDisk::IMATH_TrackletCalculatorDisk(), and trklet::IMATH_TrackletCalculatorOverlap::IMATH_TrackletCalculatorOverlap().

142  {
143  offset_ = offset;
144  double offsetI = lround(offset_ / p1_->K());
145  for (int i = 0; i < Nelements_; ++i) {
146  int i1 = addr_to_ival(i);
147  LUT[i] = gen_inv(offsetI + i1);
148  }
149 }
int gen_inv(int i)
Definition: imath.h:1024
VarBase * p1_
Definition: imath.h:298
double offset()
Definition: imath.h:1002
int addr_to_ival(int addr)
Definition: imath.h:1013
int Nelements_
Definition: imath.h:1049
double offset_
Definition: imath.h:1043
double K() const
Definition: imath.h:247
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31

◆ Ioffset()

double trklet::VarInv::Ioffset ( )
inline

Definition at line 1003 of file imath.h.

References trklet::VarBase::K(), offset_, and trklet::VarBase::p1_.

1003 { return offset_ / p1_->K(); }
VarBase * p1_
Definition: imath.h:298
double offset_
Definition: imath.h:1043
double K() const
Definition: imath.h:247

◆ ival_to_addr()

int trklet::VarInv::ival_to_addr ( int  ival)
inline

Definition at line 1012 of file imath.h.

References trklet::VarBase::ival(), mask_, and shift_.

Referenced by local_calculate().

1012 { return ((ival >> shift_) & mask_); }
unsigned int mask_
Definition: imath.h:1047
long int ival() const
Definition: imath.h:214
unsigned int shift_
Definition: imath.h:1046

◆ local_calculate()

void VarInv::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 195 of file imath_calculate.cc.

References trklet::VarBase::fval(), trklet::VarBase::fval_, trklet::VarBase::ival(), trklet::VarBase::ival_, ival_to_addr(), offset_, and trklet::VarBase::p1_.

195  {
196  fval_ = 1. / (offset_ + p1_->fval());
197  ival_ = LUT[ival_to_addr(p1_->ival())];
198 }
double fval() const
Definition: imath.h:213
VarBase * p1_
Definition: imath.h:298
int ival_to_addr(int ival)
Definition: imath.h:1012
double offset_
Definition: imath.h:1043
long int ival_
Definition: imath.h:306
long int ival() const
Definition: imath.h:214
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
double fval_
Definition: imath.h:305

◆ offset()

double trklet::VarInv::offset ( )
inline

Definition at line 1002 of file imath.h.

References offset_.

Referenced by initLUT(), and VarInv().

1002 { return offset_; }
double offset_
Definition: imath.h:1043

◆ print() [1/2]

void VarInv::print ( std::ofstream &  fs,
Verilog  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 287 of file imath_Verilog.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), mask_, trklet::VarBase::name(), trklet::VarBase::name_, nbaddr_, trklet::VarBase::nbits_, Nelements_, trklet::VarBase::p1_, shift_, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, RandomServiceHelper::t1, and RandomServiceHelper::t2.

287  {
288  assert(p1_);
289  assert(l2 == 0);
290  assert(l3 == 0);
291  std::string n1 = p1_->name();
292  if (l1 > 0)
293  n1 = n1 + "_delay" + itos(l1);
294  //first calculate address
295  std::string t1 = "addr_" + name_;
296  std::string t = "wire [" + itos(nbaddr_ - 1) + ":0] " + t1 + ";\n";
297  t = t + "assign " + t1 + " = ";
298  if (shift_ > 0)
299  t = t + "(" + n1 + ">>>" + itos(shift_) + ") & " + itos(mask_);
300  else
301  t = t + n1 + " & " + itos(mask_);
302  fs << t << "; // address for the LUT\n";
303 
304  t = "wire signed [" + itos(nbits_ - 1) + ":0] " + name_ + ";\n";
305  fs << t;
306 
307  std::string t2 = "LUT_" + name_;
308 
309  fs << "Memory #( \n";
310  fs << " .RAM_WIDTH(" << nbits_ << "), // Specify RAM data width \n";
311  fs << " .RAM_DEPTH(" << Nelements_ << "), // Specify RAM depth (number of entries) \n";
312  fs << " .RAM_PERFORMANCE(\"HIGH_PERFORMANCE\"), // \"HIGH_PERFORMANCE\" = 2 clks latency \n";
313  fs << " .INIT_FILE() \n";
314  fs << " ) " << t2 << " ( \n";
315  fs << " .addra(" << itos(nbaddr_) << "\'b0), // Write address bus, width determined from RAM_DEPTH \n";
316  fs << " .addrb(" << t1 << " ), // Read address bus, width determined from RAM_DEPTH \n";
317  fs << " .dina(" << itos(nbits_) << "\'b0), // RAM input data, width determined from RAM_WIDTH \n";
318  fs << " .clka(clk), // Write clock \n";
319  fs << " .clkb(clk), // Read clock \n";
320  fs << " .wea(1\'b0), // Write enable \n";
321  fs << " .enb(1\'b1), // Read Enable, for additional power savings, disable when not in use \n";
322  fs << " .rstb(reset), // Output reset (does not affect memory contents) \n";
323  fs << " .regceb(1\'b1), // Output register enable \n";
324  fs << " .doutb(" << name_ << ") // RAM output data, \n";
325  fs << " ); \n";
326 }
std::string name() const
Definition: imath.h:208
unsigned int mask_
Definition: imath.h:1047
VarBase * p1_
Definition: imath.h:298
assert(be >=bs)
int Nelements_
Definition: imath.h:1049
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:297
unsigned int shift_
Definition: imath.h:1046

◆ print() [2/2]

void VarInv::print ( std::ofstream &  fs,
HLS  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 260 of file imath_HLS.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), mask_, trklet::VarBase::name(), trklet::VarBase::name_, nbaddr_, trklet::VarBase::nbits_, Nelements_, trklet::VarBase::p1_, shift_, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, and RandomServiceHelper::t1.

260  {
261  assert(p1_);
262  assert(l1 == 0);
263  assert(l2 == 0);
264  assert(l3 == 0);
265 
266  fs << "static const ap_int<" << itos(nbits_) << "> LUT_" << name_ << "[" << Nelements_ << "] = {\n";
267  fs << "#include \"LUT_" << name_ << ".h\"\n";
268  fs << "};\n";
269 
270  std::string n1 = p1_->name();
271  //first calculate address
272  std::string t1 = "addr_" + name_;
273  std::string t = "const ap_uint<" + itos(nbaddr_) + "> " + t1 + " = ";
274  if (shift_ > 0)
275  t = t + "(" + n1 + ">>" + itos(shift_) + ") & " + itos(mask_);
276  else
277  t = t + n1 + " & " + itos(mask_);
278  fs << t << "; // address for the LUT\n";
279 
280  t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = LUT_" + name_ + "[addr_" + name_ + "];\n";
281  fs << t;
282 }
std::string name() const
Definition: imath.h:208
unsigned int mask_
Definition: imath.h:1047
VarBase * p1_
Definition: imath.h:298
assert(be >=bs)
int Nelements_
Definition: imath.h:1049
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:297
unsigned int shift_
Definition: imath.h:1046

◆ set_mode()

void trklet::VarInv::set_mode ( mode  m)
inline

◆ writeLUT() [1/3]

void trklet::VarInv::writeLUT ( std::ofstream &  fs) const
inline

Definition at line 1008 of file imath.h.

References compareTotals::fs, trklet::VarBase::verilog, and writeLUT().

Referenced by writeLUT().

1008 { writeLUT(fs, verilog); }
static struct trklet::VarBase::Verilog verilog
void writeLUT(std::ofstream &fs) const
Definition: imath.h:1008

◆ writeLUT() [2/3]

void VarInv::writeLUT ( std::ofstream &  fs,
Verilog   
) const

Definition at line 5 of file imath_Verilog.cc.

References TauDecayModes::dec, compareTotals::fs, mps_fire::i, trklet::VarBase::nbits_, and Nelements_.

5  {
6  for (int i = 0; i < Nelements_; ++i)
7  fs << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << "\n";
8 }
int Nelements_
Definition: imath.h:1049
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31

◆ writeLUT() [3/3]

void VarInv::writeLUT ( std::ofstream &  fs,
HLS   
) const

Definition at line 5 of file imath_HLS.cc.

References TauDecayModes::dec, compareTotals::fs, mps_fire::i, trklet::VarBase::nbits_, and Nelements_.

5  {
6  for (int i = 0; i < Nelements_ - 1; ++i)
7  fs << "0x" << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << ",\n";
8  fs << "0x" << std::hex << (LUT[Nelements_ - 1] & ((1 << nbits_) - 1)) << std::dec << "\n";
9 }
int Nelements_
Definition: imath.h:1049
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31

Member Data Documentation

◆ ashift_

unsigned int trklet::VarInv::ashift_
protected

Definition at line 1048 of file imath.h.

Referenced by addr_to_ival(), and VarInv().

◆ LUT

int* trklet::VarInv::LUT
protected

Definition at line 1052 of file imath.h.

Referenced by ~VarInv().

◆ m_

mode trklet::VarInv::m_
protected

Definition at line 1045 of file imath.h.

Referenced by addr_to_ival(), set_mode(), and VarInv().

◆ mask_

unsigned int trklet::VarInv::mask_
protected

Definition at line 1047 of file imath.h.

Referenced by ival_to_addr(), print(), and VarInv().

◆ n_

int trklet::VarInv::n_
protected

Definition at line 1044 of file imath.h.

Referenced by gen_inv(), and VarInv().

◆ nbaddr_

int trklet::VarInv::nbaddr_
protected

Definition at line 1050 of file imath.h.

Referenced by print(), and VarInv().

◆ Nelements_

int trklet::VarInv::Nelements_
protected

Definition at line 1049 of file imath.h.

Referenced by addr_to_ival(), initLUT(), print(), VarInv(), and writeLUT().

◆ offset_

double trklet::VarInv::offset_
protected

Definition at line 1043 of file imath.h.

Referenced by initLUT(), Ioffset(), local_calculate(), offset(), and VarInv().

◆ shift_

unsigned int trklet::VarInv::shift_
protected

Definition at line 1046 of file imath.h.

Referenced by addr_to_ival(), gen_inv(), ival_to_addr(), print(), and VarInv().