CMS 3D CMS Logo

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

#include <imath.h>

Inheritance diagram for trklet::VarDSPPostadd:
trklet::VarBase

Public Member Functions

void local_calculate () override
 
virtual void print (std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0)
 
virtual void print (std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0)
 
void print (std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
 
 VarDSPPostadd (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, double range=-1, int nmax=18)
 
 ~VarDSPPostadd () 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 ()
 
virtual void print (std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0)
 
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 shift3_
 
- 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 849 of file imath.h.

Constructor & Destructor Documentation

◆ VarDSPPostadd()

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

Definition at line 851 of file imath.h.

References funct::abs(), trklet::VarBase::dump_msg(), MillePedeFileConverter_cfg::e, Exception, trklet::VarBase::K(), reco::ParticleMasses::k0, 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(), trklet::VarBase::p3(), funct::pow(), ps_, trklet::VarBase::range(), and shift3_.

853  : VarBase(globals, name, p1, p2, p3, DSP_LATENCY) {
854  op_ = "DSP_postadd";
855 
856  //first, get constants for the p1*p2
857  std::map<std::string, int> map1 = p1->Kmap();
858  std::map<std::string, int> map2 = p2->Kmap();
859  for (const auto &it : map2) {
860  if (map1.find(it.first) == map1.end())
861  map1[it.first] = it.second;
862  else
863  map1[it.first] = map1[it.first] + it.second;
864  }
865  double k0 = p1->K() * p2->K();
866  int s0 = map1["2"];
867 
868  //now addition
869  std::map<std::string, int> map3 = p3->Kmap();
870  int s3 = map3["2"];
871 
872  //first check if the constants are all lined up
873  //go over the two maps subtracting the units
874  for (const auto &it : map3) {
875  if (map1.find(it.first) == map1.end())
876  map1[it.first] = -it.second;
877  else
878  map1[it.first] = map1[it.first] - it.second;
879  }
880 
881  char slog[100];
882 
883  //assert if different
884  for (const auto &it : map1) {
885  if (it.second != 0) {
886  if (it.first != "2") {
887  snprintf(slog,
888  100,
889  "VarDSPPostadd: bad units! %s^%i for variable %s",
890  (it.first).c_str(),
891  it.second,
892  name_.c_str());
893  edm::LogVerbatim("Tracklet") << slog;
894  p1->dump_msg();
895  p2->dump_msg();
896  p3->dump_msg();
897  throw cms::Exception("BadConfig") << "imath units are different!";
898  }
899  }
900  }
901 
902  double ki1 = k0 / pow(2, s0);
903  double ki2 = p3->K() / pow(2, s3);
904  //those should be the same
905  if (std::abs(ki1 / ki2 - 1.) > 1e-6) {
906  snprintf(slog, 100, "VarDSPPostadd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str());
907  edm::LogVerbatim("Tracklet") << slog;
908  p1->dump_msg();
909  p2->dump_msg();
910  p3->dump_msg();
911  throw cms::Exception("BadConfig") << "imath constants are different!";
912  }
913  //everything checks out!
914 
915  shift3_ = s3 - s0;
916  if (shift3_ < 0) {
917  throw cms::Exception("BadConfig") << "imath VarDSPPostadd: loosing precision on C in A*B+C: " << shift3_;
918  }
919 
920  Kmap_ = p3->Kmap();
921  Kmap_["2"] = Kmap_["2"] - shift3_;
922 
923  int n12 = p1->nbits() + p2->nbits();
924  int n3 = p3->nbits() + shift3_;
925  int n0 = 1 + (n12 > n3 ? n12 : n3);
926 
927  //before shifting, check the range
928  if (range > 0) {
929  n0 = log2(range / ki2 / pow(2, s3)) + 1e-9;
930  n0 = n0 + 2;
931  }
932 
933  if (n0 <= nmax) { //if it fits, we're done
934  ps_ = 0;
935  nbits_ = n0;
936  } else {
937  ps_ = n0 - nmax;
938  Kmap_["2"] = Kmap_["2"] + ps_;
939  nbits_ = nmax;
940  }
941 
942  K_ = ki2 * pow(2, Kmap_["2"]);
943  }
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
VarBase * p3() const
Definition: imath.h:211
#define DSP_LATENCY
Definition: imath.h:141
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
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~VarDSPPostadd()

trklet::VarDSPPostadd::~VarDSPPostadd ( )
overridedefault

Member Function Documentation

◆ local_calculate()

void VarDSPPostadd::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 178 of file imath_calculate.cc.

References trklet::VarBase::fval(), trklet::VarBase::fval_, trklet::VarBase::ival(), trklet::VarBase::ival_, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::p3_, ps_, and shift3_.

178  {
179  fval_ = p1_->fval() * p2_->fval() + p3_->fval();
180  ival_ = p3_->ival();
181  if (shift3_ > 0)
182  ival_ = ival_ << shift3_;
183  if (shift3_ < 0)
184  ival_ = ival_ >> (-shift3_);
185  ival_ += p1_->ival() * p2_->ival();
186  ival_ = ival_ >> ps_;
187 }
double fval() const
Definition: imath.h:212
VarBase * p1_
Definition: imath.h:297
VarBase * p2_
Definition: imath.h:298
VarBase * p3_
Definition: imath.h:299
long int ival_
Definition: imath.h:305
long int ival() const
Definition: imath.h:213
double fval_
Definition: imath.h:304

◆ print() [1/3]

virtual void trklet::VarBase::print
inline

Definition at line 259 of file imath.h.

259  {
260  fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n";
261  }

◆ print() [2/3]

virtual void trklet::VarBase::print
inline

Definition at line 256 of file imath.h.

256  {
257  fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n";
258  }

◆ print() [3/3]

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

Reimplemented from trklet::VarBase.

Definition at line 328 of file imath_Verilog.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), trklet::VarBase::name(), trklet::VarBase::name_, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::p3_, ps_, shift3_, and AlCaHLTBitMon_QueryRunRegistry::string.

328  {
329  assert(p1_);
330  assert(p2_);
331  assert(p3_);
332  std::string n1 = p1_->name();
333  if (l1 > 0)
334  n1 = n1 + "_delay" + itos(l1);
335  std::string n2 = p2_->name();
336  if (l2 > 0)
337  n2 = n2 + "_delay" + itos(l2);
338  std::string n3 = p3_->name();
339  if (l3 > 0)
340  n3 = n3 + "_delay" + itos(l3);
341 
342  if (shift3_ > 0)
343  n3 = n3 + "<<" + itos(shift3_);
344  if (shift3_ < 0)
345  n3 = n3 + ">>>" + itos(-shift3_);
346 
347  std::string n4 = "";
348  if (ps_ > 0)
349  n4 = ">>>" + itos(ps_);
350 
351  fs << name_ + " = DSP_postadd(" + n1 + ", " + n2 + ", " + n3 + ")" + n4 + ";";
352 }
std::string name() const
Definition: imath.h:207
VarBase * p1_
Definition: imath.h:297
VarBase * p2_
Definition: imath.h:298
assert(be >=bs)
VarBase * p3_
Definition: imath.h:299
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:296

Member Data Documentation

◆ ps_

int trklet::VarDSPPostadd::ps_
protected

Definition at line 951 of file imath.h.

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

◆ shift3_

int trklet::VarDSPPostadd::shift3_
protected

Definition at line 952 of file imath.h.

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