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, HLS, int l1=0, int l2=0, int l3=0) override
 
void print (std::ofstream &fs, Verilog, 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, HLS) const
 
void writeLUT (std::ofstream &fs, Verilog) 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 ()
 
bool calculate (int debug_level)
 
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, HLS)
 
void print_all (std::ofstream &fs, Verilog)
 
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_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_step (int step, std::ofstream &fs, HLS)
 
void print_step (int step, std::ofstream &fs, Verilog)
 
void print_truncation (std::string &t, const std::string &o1, const int ps, HLS) const
 
void print_truncation (std::string &t, const std::string &o1, const int ps, Verilog) 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, HLS)
 
static void design_print (const std::vector< VarBase * > &v, std::ofstream &fs, Verilog)
 
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

◆ mode

Enumerator
pos 
neg 
both 

Definition at line 957 of file imath.h.

957 { pos, neg, both };

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

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  }

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_, funct::pow(), trklet::VarBase::shift(), and shift_.

◆ ~VarInv()

trklet::VarInv::~VarInv ( )
inlineoverride

Definition at line 997 of file imath.h.

997 { delete[] LUT; }

References LUT.

Member Function Documentation

◆ addr_to_ival()

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

Definition at line 1012 of file imath.h.

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  }

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

Referenced by initLUT(), and VarInv().

◆ gen_inv()

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

Definition at line 1023 of file imath.h.

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  }

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

Referenced by initLUT(), and VarInv().

◆ initLUT()

void VarInv::initLUT ( double  offset)

◆ Ioffset()

double trklet::VarInv::Ioffset ( )
inline

Definition at line 1002 of file imath.h.

1002 { return offset_ / p1_->K(); }

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

◆ ival_to_addr()

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

Definition at line 1011 of file imath.h.

1011 { return ((ival >> shift_) & mask_); }

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

Referenced by local_calculate().

◆ local_calculate()

void VarInv::local_calculate ( )
overridevirtual

◆ offset()

double trklet::VarInv::offset ( )
inline

Definition at line 1001 of file imath.h.

1001 { return offset_; }

References offset_.

Referenced by initLUT(), and VarInv().

◆ print() [1/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.

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 }

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, submitPVValidationJobs::t, and RandomServiceHelper::t1.

◆ print() [2/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.

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 }

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, submitPVValidationJobs::t, RandomServiceHelper::t1, and RandomServiceHelper::t2.

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

1007 { writeLUT(fs, verilog); }

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

Referenced by writeLUT().

◆ writeLUT() [2/3]

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

Definition at line 5 of file imath_HLS.cc.

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 }

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

◆ writeLUT() [3/3]

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

Definition at line 5 of file imath_Verilog.cc.

5  {
6  for (int i = 0; i < Nelements_; ++i)
7  fs << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << "\n";
8 }

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

Member Data Documentation

◆ ashift_

unsigned int trklet::VarInv::ashift_
protected

Definition at line 1047 of file imath.h.

Referenced by addr_to_ival(), and VarInv().

◆ LUT

int* trklet::VarInv::LUT
protected

Definition at line 1051 of file imath.h.

Referenced by ~VarInv().

◆ m_

mode trklet::VarInv::m_
protected

Definition at line 1044 of file imath.h.

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

◆ mask_

unsigned int trklet::VarInv::mask_
protected

Definition at line 1046 of file imath.h.

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

◆ n_

int trklet::VarInv::n_
protected

Definition at line 1043 of file imath.h.

Referenced by gen_inv(), and VarInv().

◆ nbaddr_

int trklet::VarInv::nbaddr_
protected

Definition at line 1049 of file imath.h.

Referenced by print(), and VarInv().

◆ Nelements_

int trklet::VarInv::Nelements_
protected

Definition at line 1048 of file imath.h.

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

◆ offset_

double trklet::VarInv::offset_
protected

Definition at line 1042 of file imath.h.

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

◆ shift_

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().

trklet::VarBase::fval
double fval() const
Definition: imath.h:212
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
trklet::VarInv::both
Definition: imath.h:957
trklet::VarInv::writeLUT
void writeLUT(std::ofstream &fs) const
Definition: imath.h:1007
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
trklet::VarBase::name
std::string name() const
Definition: imath.h:207
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
trklet::VarInv::LUT
int * LUT
Definition: imath.h:1051
trklet::VarInv::m_
mode m_
Definition: imath.h:1044
reco::HaloData::both
Definition: HaloData.h:14
cms::cuda::assert
assert(be >=bs)
trklet::VarBase::nbits
int nbits() const
Definition: imath.h:243
trklet::VarInv::nbaddr_
int nbaddr_
Definition: imath.h:1049
trklet::VarBase::p1_
VarBase * p1_
Definition: imath.h:297
trklet::VarBase::verilog
static struct trklet::VarBase::Verilog verilog
trklet::VarInv::ashift_
unsigned int ashift_
Definition: imath.h:1047
trklet::VarBase::VarBase
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
trklet::VarInv::mask_
unsigned int mask_
Definition: imath.h:1046
trklet::VarInv::gen_inv
int gen_inv(int i)
Definition: imath.h:1023
trklet::VarInv::pos
Definition: imath.h:957
trklet::VarInv::shift_
unsigned int shift_
Definition: imath.h:1045
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
generateTowerEtThresholdLUT.addr
addr
Definition: generateTowerEtThresholdLUT.py:57
trklet::VarBase::shift
int shift() const
Definition: imath.h:247
trklet::VarBase::p1
VarBase * p1() const
Definition: imath.h:209
trklet::VarBase::op_
std::string op_
Definition: imath.h:300
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
trklet::VarBase::Kmap
std::map< std::string, int > Kmap() const
Definition: imath.h:244
trklet::VarBase::itos
static std::string itos(int i)
Definition: imath.cc:16
trklet::VarBase::ival_
long int ival_
Definition: imath.h:305
trklet::VarBase::K
double K() const
Definition: imath.h:246
createfilelist.int
int
Definition: createfilelist.py:10
trklet::VarInv::offset_
double offset_
Definition: imath.h:1042
trklet::VarBase::ival
long int ival() const
Definition: imath.h:213
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::VarBase::Kmap_
std::map< std::string, int > Kmap_
Definition: imath.h:313
trklet::VarInv::Nelements_
int Nelements_
Definition: imath.h:1048
LUT_LATENCY
#define LUT_LATENCY
Definition: imath.h:140
LUT
std::vector< unsigned short int > LUT
Definition: DTTracoLUTs.h:31
trklet::VarBase::name_
std::string name_
Definition: imath.h:296
trklet::VarBase::K_
double K_
Definition: imath.h:312
trklet::VarInv::offset
double offset()
Definition: imath.h:1001
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
trklet::VarInv::ival_to_addr
int ival_to_addr(int ival)
Definition: imath.h:1011
trklet::VarBase::nbits_
int nbits_
Definition: imath.h:311
trklet::VarInv::neg
Definition: imath.h:957
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
trklet::VarInv::addr_to_ival
int addr_to_ival(int addr)
Definition: imath.h:1012
trklet::VarInv::n_
int n_
Definition: imath.h:1043
trklet::VarBase::fval_
double fval_
Definition: imath.h:304