CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ()
 
bool calculate (int debug_level)
 
bool calculate ()
 
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 955 of file imath.h.

Member Enumeration Documentation

Enumerator
pos 
neg 
both 

Definition at line 957 of file imath.h.

Constructor & Destructor Documentation

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 959 of file imath.h.

References addr_to_ival(), ashift_, reco::HaloData::both, gen_inv(), mps_fire::i, 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_, funct::pow(), trklet::VarBase::shift(), and shift_.

968  : VarBase(globals, name, p1, nullptr, nullptr, LUT_LATENCY) {
969  op_ = "inv";
970  offset_ = offset;
971  nbits_ = nbits;
972  n_ = n;
973  shift_ = shift;
974  m_ = m;
975  if (nbaddr < 0)
976  nbaddr = p1->nbits();
977  nbaddr_ = nbaddr - shift;
978  if (m_ != mode::both)
979  nbaddr_--;
980  Nelements_ = 1 << nbaddr_;
981  mask_ = Nelements_ - 1;
982  ashift_ = sizeof(int) * 8 - nbaddr_;
983 
984  const std::map<std::string, int> map1 = p1->Kmap();
985  for (const auto &it : map1)
986  Kmap_[it.first] = -it.second;
987  Kmap_["2"] = Kmap_["2"] - n;
988  K_ = pow(2, -n) / p1->K();
989 
990  LUT = new int[Nelements_];
991  double offsetI = lround(offset_ / p1_->K());
992  for (int i = 0; i < Nelements_; ++i) {
993  int i1 = addr_to_ival(i);
994  LUT[i] = gen_inv(offsetI + i1);
995  }
996  }
int gen_inv(int i)
Definition: imath.h:1023
unsigned int mask_
Definition: imath.h:1046
VarBase * p1_
Definition: imath.h:297
double offset()
Definition: imath.h:1001
double K() const
Definition: imath.h:246
int addr_to_ival(int addr)
Definition: imath.h:1012
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
std::string op_
Definition: imath.h:300
int Nelements_
Definition: imath.h:1048
VarBase * p1() const
Definition: imath.h:209
double offset_
Definition: imath.h:1042
unsigned int ashift_
Definition: imath.h:1047
#define LUT_LATENCY
Definition: imath.h:140
int nbits() const
Definition: imath.h:243
int shift() const
Definition: imath.h:247
std::string name() const
Definition: imath.h:207
std::map< std::string, int > Kmap_
Definition: imath.h:313
double K_
Definition: imath.h:312
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
unsigned int shift_
Definition: imath.h:1045
std::map< std::string, int > Kmap() const
Definition: imath.h:244
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
trklet::VarInv::~VarInv ( )
inlineoverride

Definition at line 997 of file imath.h.

References LUT.

997 { delete[] LUT; }
int * LUT
Definition: imath.h:1051

Member Function Documentation

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

Definition at line 1012 of file imath.h.

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

Referenced by initLUT(), and VarInv().

1012  {
1013  switch (m_) {
1014  case mode::pos:
1015  return addr << shift_;
1016  case mode::neg:
1017  return (addr - Nelements_) << shift_;
1018  case mode::both:
1019  return (addr << ashift_) >> (ashift_ - shift_);
1020  }
1021  assert(0);
1022  }
assert(be >=bs)
int Nelements_
Definition: imath.h:1048
unsigned int ashift_
Definition: imath.h:1047
unsigned int shift_
Definition: imath.h:1045
int trklet::VarInv::gen_inv ( int  i)
inline

Definition at line 1023 of file imath.h.

References mps_fire::i, n_, trklet::VarBase::nbits_, and shift_.

Referenced by initLUT(), and VarInv().

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

Definition at line 142 of file imath.cc.

References addr_to_ival(), gen_inv(), mps_fire::i, 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:1023
VarBase * p1_
Definition: imath.h:297
double offset()
Definition: imath.h:1001
double K() const
Definition: imath.h:246
int addr_to_ival(int addr)
Definition: imath.h:1012
int Nelements_
Definition: imath.h:1048
double offset_
Definition: imath.h:1042
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
double trklet::VarInv::Ioffset ( )
inline

Definition at line 1002 of file imath.h.

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

1002 { return offset_ / p1_->K(); }
VarBase * p1_
Definition: imath.h:297
double K() const
Definition: imath.h:246
double offset_
Definition: imath.h:1042
int trklet::VarInv::ival_to_addr ( int  ival)
inline

Definition at line 1011 of file imath.h.

References mask_, and shift_.

Referenced by local_calculate().

1011 { return ((ival >> shift_) & mask_); }
long int ival() const
Definition: imath.h:213
unsigned int mask_
Definition: imath.h:1046
unsigned int shift_
Definition: imath.h:1045
void VarInv::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 189 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_.

189  {
190  fval_ = 1. / (offset_ + p1_->fval());
191  ival_ = LUT[ival_to_addr(p1_->ival())];
192 }
long int ival() const
Definition: imath.h:213
VarBase * p1_
Definition: imath.h:297
int ival_to_addr(int ival)
Definition: imath.h:1011
double offset_
Definition: imath.h:1042
long int ival_
Definition: imath.h:305
double fval() const
Definition: imath.h:212
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
double fval_
Definition: imath.h:304
double trklet::VarInv::offset ( )
inline

Definition at line 1001 of file imath.h.

References offset_.

Referenced by initLUT(), and VarInv().

1001 { return offset_; }
double offset_
Definition: imath.h:1042
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(), trklet::VarBase::itos(), mask_, trklet::VarBase::name(), trklet::VarBase::name_, nbaddr_, trklet::VarBase::nbits_, Nelements_, trklet::VarBase::p1_, shift_, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

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 }
unsigned int mask_
Definition: imath.h:1046
VarBase * p1_
Definition: imath.h:297
assert(be >=bs)
int Nelements_
Definition: imath.h:1048
static std::string itos(int i)
Definition: imath.cc:16
std::string name() const
Definition: imath.h:207
std::string name_
Definition: imath.h:296
unsigned int shift_
Definition: imath.h:1045
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(), trklet::VarBase::itos(), mask_, trklet::VarBase::name(), trklet::VarBase::name_, nbaddr_, trklet::VarBase::nbits_, Nelements_, trklet::VarBase::p1_, shift_, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

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 }
unsigned int mask_
Definition: imath.h:1046
VarBase * p1_
Definition: imath.h:297
assert(be >=bs)
int Nelements_
Definition: imath.h:1048
static std::string itos(int i)
Definition: imath.cc:16
std::string name() const
Definition: imath.h:207
std::string name_
Definition: imath.h:296
unsigned int shift_
Definition: imath.h:1045
void trklet::VarInv::set_mode ( mode  m)
inline
void trklet::VarInv::writeLUT ( std::ofstream &  fs) const
inline

Definition at line 1007 of file imath.h.

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

Referenced by trklet::TrackletCalculator::TrackletCalculator(), and writeLUT().

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

Definition at line 5 of file imath_Verilog.cc.

References TauDecayModes::dec, 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:1048
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
void VarInv::writeLUT ( std::ofstream &  fs,
HLS   
) const

Definition at line 5 of file imath_HLS.cc.

References TauDecayModes::dec, 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:1048
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31

Member Data Documentation

unsigned int trklet::VarInv::ashift_
protected

Definition at line 1047 of file imath.h.

Referenced by addr_to_ival(), and VarInv().

int* trklet::VarInv::LUT
protected

Definition at line 1051 of file imath.h.

Referenced by ~VarInv().

mode trklet::VarInv::m_
protected

Definition at line 1044 of file imath.h.

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

unsigned int trklet::VarInv::mask_
protected

Definition at line 1046 of file imath.h.

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

int trklet::VarInv::n_
protected

Definition at line 1043 of file imath.h.

Referenced by gen_inv(), and VarInv().

int trklet::VarInv::nbaddr_
protected

Definition at line 1049 of file imath.h.

Referenced by print(), and VarInv().

int trklet::VarInv::Nelements_
protected

Definition at line 1048 of file imath.h.

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

double trklet::VarInv::offset_
protected

Definition at line 1042 of file imath.h.

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

unsigned int trklet::VarInv::shift_
protected

Definition at line 1045 of file imath.h.

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