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

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 (std::vector< VarBase * > v, std::ofstream &fs, HLS)
 
static void design_print (std::vector< VarBase * > v, std::ofstream &fs, Verilog)
 
static void hls_print (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 (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.

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  }

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(), indexGen::s2, shift1, and shift2.

◆ ~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.

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 }

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.

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

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 }

References cms::cuda::assert(), 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 OrderedSet::t.

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

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 }

References cms::cuda::assert(), 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, OrderedSet::t, and trklet::VarBase::verilog.

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

trklet::VarBase::fval
double fval() const
Definition: imath.h:212
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
trklet::VarAdd::shift1
int shift1
Definition: imath.h:594
trklet::VarBase::name
std::string name() const
Definition: imath.h:207
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
n0
int n0
Definition: AMPTWrapper.h:44
cms::cuda::assert
assert(be >=bs)
trklet::VarBase::p2_
VarBase * p2_
Definition: imath.h:298
trklet::VarBase::kstring
std::string kstring() const
Definition: imath.cc:18
trklet::VarBase::range
double range() const
Definition: imath.h:245
trklet::VarBase::nbits
int nbits() const
Definition: imath.h:243
indexGen.s2
s2
Definition: indexGen.py:107
trklet::VarBase::p1_
VarBase * p1_
Definition: imath.h:297
trklet::VarBase::verilog
static struct trklet::VarBase::Verilog verilog
trklet::VarAdd::shift2
int shift2
Definition: imath.h:595
trklet::VarBase::VarBase
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
trklet::VarBase::p1
VarBase * p1() const
Definition: imath.h:209
trklet::VarBase::op_
std::string op_
Definition: imath.h:300
trklet::VarBase::Kmap
std::map< std::string, int > Kmap() const
Definition: imath.h:244
CastorDigiReco.o1
o1
Definition: CastorDigiReco.py:84
OrderedSet.t
t
Definition: OrderedSet.py:90
trklet::VarBase::itos
static std::string itos(int i)
Definition: imath.cc:16
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::VarBase::ival_
long int ival_
Definition: imath.h:305
trklet::VarBase::K
double K() const
Definition: imath.h:246
trklet::VarBase::dump_msg
void dump_msg()
Definition: imath.cc:96
edm::LogVerbatim
Definition: MessageLogger.h:297
trklet::VarBase::ival
long int ival() const
Definition: imath.h:213
trklet::VarBase::Kmap_
std::map< std::string, int > Kmap_
Definition: imath.h:313
trklet::VarBase::p2
VarBase * p2() const
Definition: imath.h:210
trklet::VarBase::hls
static struct trklet::VarBase::HLS hls
trklet::VarAdd::ps_
int ps_
Definition: imath.h:593
trklet::VarBase::print_truncation
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
Definition: imath_Verilog.cc:10
trklet::VarBase::name_
std::string name_
Definition: imath.h:296
Exception
Definition: hltDiff.cc:246
trklet::VarBase::K_
double K_
Definition: imath.h:312
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::VarBase::nbits_
int nbits_
Definition: imath.h:311
trklet::VarBase::fval_
double fval_
Definition: imath.h:304
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37