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 511 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 513 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.

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

◆ 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:207
VarBase * p1_
Definition: imath.h:297
VarBase * p2_
Definition: imath.h:298
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:312
int shift1
Definition: imath.h:594
int shift2
Definition: imath.h:595

◆ 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:207
VarBase * p1_
Definition: imath.h:297
VarBase * p2_
Definition: imath.h:298
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:312
int shift1
Definition: imath.h:594
int shift2
Definition: imath.h:595

Member Data Documentation

◆ ps_

int trklet::VarAdd::ps_
protected

Definition at line 593 of file imath.h.

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

◆ shift1

int trklet::VarAdd::shift1
protected

Definition at line 594 of file imath.h.

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

◆ shift2

int trklet::VarAdd::shift2
protected

Definition at line 595 of file imath.h.

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