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 ()
 
void calcDebug (int debug_level, long int ival_prev, bool &all_ok)
 
bool calculate (int debug_level=0)
 
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 850 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 852 of file imath.h.

References funct::abs(), trklet::VarBase::dump_msg(), MillePedeFileConverter_cfg::e, Exception, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, 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_.

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

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

184  {
185  fval_ = p1_->fval() * p2_->fval() + p3_->fval();
186  ival_ = p3_->ival();
187  if (shift3_ > 0)
189  if (shift3_ < 0)
190  ival_ = ival_ >> (-shift3_);
191  ival_ += p1_->ival() * p2_->ival();
192  ival_ = ival_ >> ps_;
193 }
double fval() const
Definition: imath.h:213
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
VarBase * p3_
Definition: imath.h:300
long int ival_
Definition: imath.h:306
long int ival() const
Definition: imath.h:214
double fval_
Definition: imath.h:305
int bitShift(int num, int bits)
Definition: BitShift.h:6

◆ print() [1/3]

virtual void trklet::VarBase::print
inline

Definition at line 260 of file imath.h.

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

◆ print() [2/3]

virtual void trklet::VarBase::print
inline

Definition at line 257 of file imath.h.

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

◆ 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(), make_classfiles::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:208
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
assert(be >=bs)
VarBase * p3_
Definition: imath.h:300
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:297

Member Data Documentation

◆ ps_

int trklet::VarDSPPostadd::ps_
protected

Definition at line 952 of file imath.h.

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

◆ shift3_

int trklet::VarDSPPostadd::shift3_
protected

Definition at line 953 of file imath.h.

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