CMS 3D CMS Logo

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

#include <imath.h>

Inheritance diagram for trklet::VarSubtract:
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
 
 VarSubtract (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
 
 ~VarSubtract () 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 ()
 
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 599 of file imath.h.

Constructor & Destructor Documentation

◆ VarSubtract()

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

Definition at line 601 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(), conifer::pow(), ps_, trklet::VarBase::range(), shift1, and shift2.

602  : VarBase(globals, name, p1, p2, nullptr, 1) {
603  op_ = "subtract";
604 
605  std::map<std::string, int> map1 = p1->Kmap();
606  std::map<std::string, int> map2 = p2->Kmap();
607  int s1 = map1["2"];
608  int s2 = map2["2"];
609 
610  //first check if the constants are all lined up go over the two maps subtracting the units
611  for (const auto &it : map2) {
612  if (map1.find(it.first) == map1.end())
613  map1[it.first] = -it.second;
614  else
615  map1[it.first] = map1[it.first] - it.second;
616  }
617 
618  char slog[100];
619 
620  //assert if different
621  for (const auto &it : map1) {
622  if (it.second != 0) {
623  if (it.first != "2") {
624  snprintf(
625  slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str());
626  edm::LogVerbatim("Tracklet") << slog;
627  p1->dump_msg();
628  p2->dump_msg();
629  throw cms::Exception("BadConfig") << "imath units are different!";
630  }
631  }
632  }
633 
634  double ki1 = p1->K() / pow(2, s1);
635  double ki2 = p2->K() / pow(2, s2);
636  //those should be the same
637  if (std::abs(ki1 / ki2 - 1.) > 1e-6) {
638  snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str());
639  edm::LogVerbatim("Tracklet") << slog;
640  p1->dump_msg();
641  p2->dump_msg();
642  throw cms::Exception("BadConfig") << "imath constants are different!";
643  }
644  //everything checks out!
645 
646  Kmap_ = p1->Kmap();
647 
648  int s0 = s1 < s2 ? s1 : s2;
649  shift1 = s1 - s0;
650  shift2 = s2 - s0;
651 
652  int n1 = p1->nbits() + shift1;
653  int n2 = p2->nbits() + shift2;
654  int n0 = 1 + (n1 > n2 ? n1 : n2);
655 
656  //before shifting, check the range
657  if (range > 0) {
658  n0 = log2(range / ki1 / pow(2, s0)) + 1e-9;
659  n0 = n0 + 2;
660  }
661 
662  if (n0 <= nmax) { //if it fits, we're done
663  ps_ = 0;
664  Kmap_["2"] = s0;
665  nbits_ = n0;
666  } else {
667  ps_ = n0 - nmax;
668  Kmap_["2"] = s0 + ps_;
669  nbits_ = nmax;
670  }
671 
672  K_ = ki1 * pow(2, Kmap_["2"]);
673  }
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
constexpr int pow(int x)
Definition: conifer.h:24
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
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

◆ ~VarSubtract()

trklet::VarSubtract::~VarSubtract ( )
overridedefault

Member Function Documentation

◆ local_calculate()

void VarSubtract::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 133 of file imath_calculate.cc.

References l1t::bitShift(), 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.

133  {
134  fval_ = p1_->fval() - p2_->fval();
135  long int i1 = p1_->ival();
136  long int i2 = p2_->ival();
137  if (shift1 > 0)
139  if (shift2 > 0)
141  ival_ = i1 - i2;
142  if (ps_ > 0)
143  ival_ = ival_ >> ps_;
144 }
double fval() const
Definition: imath.h:213
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
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/2]

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

Reimplemented from trklet::VarBase.

Definition at line 164 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.

164  {
165  assert(p1_);
166  assert(p2_);
167  assert(l3 == 0);
168  std::string o1 = p1_->name();
169  if (l1 > 0)
170  o1 += "_delay" + itos(l1);
171  if (shift1 > 0) {
172  o1 += "<<" + itos(shift1);
173  o1 = "(" + o1 + ")";
174  }
175 
176  std::string o2 = p2_->name();
177  if (l2 > 0)
178  o2 += "_delay" + itos(l2);
179  if (shift2 > 0) {
180  o2 += "<<" + itos(shift2);
181  o2 = "(" + o2 + ")";
182  }
183 
184  o1 = o1 + " - " + o2;
185 
186  std::string t = "";
188  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
189 }
std::string name() const
Definition: imath.h:208
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
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:313

◆ print() [2/2]

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

Reimplemented from trklet::VarBase.

Definition at line 147 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.

147  {
148  assert(p1_);
149  assert(p2_);
150  assert(l1 == 0);
151  assert(l2 == 0);
152  assert(l3 == 0);
153  std::string o1 = p1_->name();
154  if (shift1 > 0) {
155  o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")";
156  o1 += "<<" + itos(shift1);
157  o1 = "(" + o1 + ")";
158  }
159 
160  std::string o2 = p2_->name();
161  if (shift2 > 0) {
162  o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")";
163  o2 += "<<" + itos(shift2);
164  o2 = "(" + o2 + ")";
165  }
166 
167  o1 = o1 + " - " + o2;
168 
169  std::string t = "";
171  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
172 }
std::string name() const
Definition: imath.h:208
VarBase * p1_
Definition: imath.h:298
VarBase * p2_
Definition: imath.h:299
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:313

Member Data Documentation

◆ ps_

int trklet::VarSubtract::ps_
protected

Definition at line 682 of file imath.h.

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

◆ shift1

int trklet::VarSubtract::shift1
protected

Definition at line 683 of file imath.h.

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

◆ shift2

int trklet::VarSubtract::shift2
protected

Definition at line 684 of file imath.h.

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