CMS 3D CMS Logo

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

#include <imath.h>

Inheritance diagram for trklet::VarAdd:
trklet::VarBase

Public Member Functions

void local_calculate () override
 
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
 
 VarAdd (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
 
 ~VarAdd () override=default
 
- 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

int ps_
 
int shift1
 
int shift2
 
- 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 512 of file imath.h.

Constructor & Destructor Documentation

◆ VarAdd()

trklet::VarAdd::VarAdd ( imathGlobals globals,
std::string  name,
VarBase p1,
VarBase p2,
double  range = -1,
int  nmax = 18 
)
inline

Definition at line 514 of file imath.h.

References funct::abs(), trklet::VarBase::dump_msg(), MillePedeFileConverter_cfg::e, Exception, trklet::VarBase::K(), trklet::VarBase::K_, trklet::VarBase::Kmap(), trklet::VarBase::Kmap_, n0, trklet::VarBase::name_, trklet::VarBase::nbits(), trklet::VarBase::nbits_, trklet::VarBase::op_, trklet::VarBase::p1(), trklet::VarBase::p2(), funct::pow(), ps_, trklet::VarBase::range(), shift1, and shift2.

515  : VarBase(globals, name, p1, p2, nullptr, 1) {
516  op_ = "add";
517 
518  std::map<std::string, int> map1 = p1->Kmap();
519  std::map<std::string, int> map2 = p2->Kmap();
520  int s1 = map1["2"];
521  int s2 = map2["2"];
522 
523  //first check if the constants are all lined up
524  //go over the two maps subtracting the units
525  for (const auto &it : map2) {
526  if (map1.find(it.first) == map1.end())
527  map1[it.first] = -it.second;
528  else
529  map1[it.first] = map1[it.first] - it.second;
530  }
531 
532  char slog[100];
533 
534  //assert if different
535  for (const auto &it : map1) {
536  if (it.second != 0) {
537  if (it.first != "2") {
538  snprintf(
539  slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str());
540  edm::LogVerbatim("Tracklet") << slog;
541  p1->dump_msg();
542  p2->dump_msg();
543  throw cms::Exception("BadConfig") << "imath units are different!";
544  }
545  }
546  }
547 
548  double ki1 = p1->K() / pow(2, s1);
549  double ki2 = p2->K() / pow(2, s2);
550  //those should be the same
551  if (std::abs(ki1 / ki2 - 1.) > 1e-6) {
552  snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str());
553  edm::LogVerbatim("Tracklet") << slog;
554  p1->dump_msg();
555  p2->dump_msg();
556  throw cms::Exception("BadConfig") << "imath constants are different!";
557  }
558  //everything checks out!
559 
560  Kmap_ = p1->Kmap();
561 
562  int s0 = s1 < s2 ? s1 : s2;
563  shift1 = s1 - s0;
564  shift2 = s2 - s0;
565 
566  int n1 = p1->nbits() + shift1;
567  int n2 = p2->nbits() + shift2;
568  int n0 = 1 + (n1 > n2 ? n1 : n2);
569 
570  //before shifting, check the range
571  if (range > 0) {
572  n0 = log2(range / ki1 / pow(2, s0)) + 1e-9;
573  n0 = n0 + 2;
574  }
575 
576  if (n0 <= nmax) { //if it fits, we're done
577  ps_ = 0;
578  Kmap_["2"] = s0;
579  nbits_ = n0;
580  } else {
581  ps_ = n0 - nmax;
582  Kmap_["2"] = s0 + ps_;
583  nbits_ = nmax;
584  }
585 
586  K_ = ki1 * pow(2, Kmap_["2"]);
587  }
Log< level::Info, true > LogVerbatim
std::string name() const
Definition: imath.h:208
double range() const
Definition: imath.h:246
int nbits() const
Definition: imath.h:244
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 n0
Definition: AMPTWrapper.h:44
VarBase * p1() const
Definition: imath.h:210
std::map< std::string, int > Kmap() const
Definition: imath.h:245
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void dump_msg()
Definition: imath.cc:96
double K() const
Definition: imath.h:247
std::string name_
Definition: imath.h:297
std::map< std::string, int > Kmap_
Definition: imath.h:314
VarBase * p2() const
Definition: imath.h:211
double K_
Definition: imath.h:313
int shift1
Definition: imath.h:595
int shift2
Definition: imath.h:596
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~VarAdd()

trklet::VarAdd::~VarAdd ( )
overridedefault

Member Function Documentation

◆ local_calculate()

void VarAdd::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 114 of file imath_calculate.cc.

References l1t::bitShift(), trklet::VarBase::fval(), trklet::VarBase::fval_, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, trklet::VarBase::ival(), trklet::VarBase::ival_, trklet::VarBase::p1_, trklet::VarBase::p2_, ps_, shift1, and shift2.

114  {
115  fval_ = p1_->fval() + p2_->fval();
116  long int i1 = p1_->ival();
117  long int i2 = p2_->ival();
118  if (shift1 > 0)
120  if (shift2 > 0)
122  ival_ = i1 + i2;
123  if (ps_ > 0)
124  ival_ = ival_ >> ps_;
125 }
double fval() const
Definition: imath.h:213
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
long int ival_
Definition: imath.h:306
long int ival() const
Definition: imath.h:214
int shift1
Definition: imath.h:595
int shift2
Definition: imath.h:596
double fval_
Definition: imath.h:305
int bitShift(int num, int bits)
Definition: BitShift.h:6

◆ print() [1/2]

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

Reimplemented from trklet::VarBase.

Definition at line 137 of file imath_Verilog.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), trklet::VarBase::name(), trklet::VarBase::nbits_, CastorDigiReco::o1, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::print_truncation(), ps_, shift1, shift2, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, and trklet::VarBase::verilog.

137  {
138  assert(p1_);
139  assert(p2_);
140  assert(l3 == 0);
141  std::string o1 = p1_->name();
142  if (l1 > 0)
143  o1 += "_delay" + itos(l1);
144  if (shift1 > 0) {
145  o1 += "<<" + itos(shift1);
146  o1 = "(" + o1 + ")";
147  }
148 
149  std::string o2 = p2_->name();
150  if (l2 > 0)
151  o2 += "_delay" + itos(l2);
152  if (shift2 > 0) {
153  o2 += "<<" + itos(shift2);
154  o2 = "(" + o2 + ")";
155  }
156 
157  o1 = o1 + " + " + o2;
158 
159  std::string t = "";
161  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
162 }
std::string name() const
Definition: imath.h:208
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
std::string kstring() const
Definition: imath.cc:18
assert(be >=bs)
static struct trklet::VarBase::Verilog verilog
static std::string itos(int i)
Definition: imath.cc:16
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
double K_
Definition: imath.h:313
int shift1
Definition: imath.h:595
int shift2
Definition: imath.h:596

◆ print() [2/2]

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

Reimplemented from trklet::VarBase.

Definition at line 120 of file imath_HLS.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::hls, trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), trklet::VarBase::name(), trklet::VarBase::nbits_, CastorDigiReco::o1, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::print_truncation(), ps_, shift1, shift2, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

120  {
121  assert(p1_);
122  assert(p2_);
123  assert(l1 == 0);
124  assert(l2 == 0);
125  assert(l3 == 0);
126  std::string o1 = p1_->name();
127  if (shift1 > 0) {
128  o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")";
129  o1 += "<<" + itos(shift1);
130  o1 = "(" + o1 + ")";
131  }
132 
133  std::string o2 = p2_->name();
134  if (shift2 > 0) {
135  o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")";
136  o2 += "<<" + itos(shift2);
137  o2 = "(" + o2 + ")";
138  }
139 
140  o1 = o1 + " + " + o2;
141 
142  std::string t = "";
144  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
145 }
std::string name() const
Definition: imath.h:208
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
std::string kstring() const
Definition: imath.cc:18
assert(be >=bs)
static std::string itos(int i)
Definition: imath.cc:16
static struct trklet::VarBase::HLS hls
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
double K_
Definition: imath.h:313
int shift1
Definition: imath.h:595
int shift2
Definition: imath.h:596

Member Data Documentation

◆ ps_

int trklet::VarAdd::ps_
protected

Definition at line 594 of file imath.h.

Referenced by local_calculate(), print(), and VarAdd().

◆ shift1

int trklet::VarAdd::shift1
protected

Definition at line 595 of file imath.h.

Referenced by local_calculate(), print(), and VarAdd().

◆ shift2

int trklet::VarAdd::shift2
protected

Definition at line 596 of file imath.h.

Referenced by local_calculate(), print(), and VarAdd().