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, HLS, int l1=0, int l2=0, int l3=0)
 
virtual void print (std::ofstream &fs, Verilog, 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 ()
 
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 ()
 
virtual void print (std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0)
 
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 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, HLS)
 
static void design_print (const std::vector< VarBase * > &v, std::ofstream &fs, Verilog)
 
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.

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  }

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_.

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

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 }

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_.

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

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 }

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

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

trklet::VarBase::fval
double fval() const
Definition: imath.h:212
trklet::VarBase::name
std::string name() const
Definition: imath.h:207
reco::ParticleMasses::k0
const double k0
Definition: ParticleMasses.h:7
n0
int n0
Definition: AMPTWrapper.h:44
cms::cuda::assert
assert(be >=bs)
trklet::VarBase::p2_
VarBase * p2_
Definition: imath.h:298
trklet::VarBase::range
double range() const
Definition: imath.h:245
trklet::VarBase::nbits
int nbits() const
Definition: imath.h:243
trklet::VarBase::p1_
VarBase * p1_
Definition: imath.h:297
trklet::VarBase::VarBase
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
trklet::VarDSPPostadd::shift3_
int shift3_
Definition: imath.h:952
DSP_LATENCY
#define DSP_LATENCY
Definition: imath.h:141
trklet::VarBase::p1
VarBase * p1() const
Definition: imath.h:209
trklet::VarBase::p3_
VarBase * p3_
Definition: imath.h:299
trklet::VarBase::op_
std::string op_
Definition: imath.h:300
trklet::VarBase::Kmap
std::map< std::string, int > Kmap() const
Definition: imath.h:244
callgraph.n2
n2
Definition: callgraph.py:50
trklet::VarBase::itos
static std::string itos(int i)
Definition: imath.cc:16
trklet::VarBase::ival_
long int ival_
Definition: imath.h:305
trklet::VarBase::p3
VarBase * p3() const
Definition: imath.h:211
trklet::VarBase::K
double K() const
Definition: imath.h:246
trklet::VarBase::dump_msg
void dump_msg()
Definition: imath.cc:96
trklet::VarDSPPostadd::ps_
int ps_
Definition: imath.h:951
trklet::VarBase::ival
long int ival() const
Definition: imath.h:213
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::VarBase::Kmap_
std::map< std::string, int > Kmap_
Definition: imath.h:313
trklet::VarBase::p2
VarBase * p2() const
Definition: imath.h:210
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
trklet::VarBase::name_
std::string name_
Definition: imath.h:296
Exception
Definition: hltDiff.cc:245
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:29
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